Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Thread Minimize Application

Thread Minimize Application

Scheduled Pinned Locked Moved Visual Basic
help
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LeandroABorges
    wrote on last edited by
    #1

    Hi everyone, I´m programming an application win forms and in some parts of my application I have a strong processing module, and I´ve decided do make a loading screen. So, i´ve done it:

      Private Sub ShowLoading()
        Dim frmBlank As New frmBlank
        frmBlank.Cursor = Cursors.WaitCursor
        frmBlank.Show()
        Dim frmLoading As New frmLoading
        frmLoading.ShowDialog()
      End Sub
    
      Private Sub StartLoadingThread()
        thread = New Threading.Thread(AddressOf ShowLoading)
        thread.Start()
      End Sub
    
      Private Sub StopLoadingThread()
        thread.Abort()
      End Sub
    

    But, the problems appear, when i abort the thread, the loading form closes, as it have to close, but the whole application minimizes. I´m using the form in a Class Library, and it start maximized. THe whole think works as it have to work perfectly, but the problem is the application minimize. Thanks everyone!

    ----- LeandroAB

    D 1 Reply Last reply
    0
    • L LeandroABorges

      Hi everyone, I´m programming an application win forms and in some parts of my application I have a strong processing module, and I´ve decided do make a loading screen. So, i´ve done it:

        Private Sub ShowLoading()
          Dim frmBlank As New frmBlank
          frmBlank.Cursor = Cursors.WaitCursor
          frmBlank.Show()
          Dim frmLoading As New frmLoading
          frmLoading.ShowDialog()
        End Sub
      
        Private Sub StartLoadingThread()
          thread = New Threading.Thread(AddressOf ShowLoading)
          thread.Start()
        End Sub
      
        Private Sub StopLoadingThread()
          thread.Abort()
        End Sub
      

      But, the problems appear, when i abort the thread, the loading form closes, as it have to close, but the whole application minimizes. I´m using the form in a Class Library, and it start maximized. THe whole think works as it have to work perfectly, but the problem is the application minimize. Thanks everyone!

      ----- LeandroAB

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Why are you show the loading form on a seperate thread? From what you're describing, you wouldn't need any threading at all. Also, why is the "Loading..." form being shown as a dialog?? and I have no idea what frmBlank is for. From your description, it should be a simple matter of creating and showing a "Loading..." form, doing your work, then destroying the "Loading..." form. Creating forms and show ing in anything other than the UI thread is not a good idea, as you've found out from your weird side-effects.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      L 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Why are you show the loading form on a seperate thread? From what you're describing, you wouldn't need any threading at all. Also, why is the "Loading..." form being shown as a dialog?? and I have no idea what frmBlank is for. From your description, it should be a simple matter of creating and showing a "Loading..." form, doing your work, then destroying the "Loading..." form. Creating forms and show ing in anything other than the UI thread is not a good idea, as you've found out from your weird side-effects.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        L Offline
        L Offline
        LeandroABorges
        wrote on last edited by
        #3

        Let me try to explain more detailed my problem. I have a very long process, and I don´t want to lock the screen without a message. So I did a loading form, that has only one label: "Loading..." When i start the process, the form was displayed, and when the process ends, i have to close the form. Thats the reason that i habve to use a thread, because i have to continue with my process in background. The frmBlank is only used to stay between the application and the loading form, without its the problem continues ocurring. When i kill the thread, the forms closes automaticaly, but i´ve tried to close mannualy the form in the thread, and the problems continues ocurring. I show the form as a dialog, to block the user access to the system during the process. Thanks for your time.

        ----- LeandroAB

        D 1 Reply Last reply
        0
        • L LeandroABorges

          Let me try to explain more detailed my problem. I have a very long process, and I don´t want to lock the screen without a message. So I did a loading form, that has only one label: "Loading..." When i start the process, the form was displayed, and when the process ends, i have to close the form. Thats the reason that i habve to use a thread, because i have to continue with my process in background. The frmBlank is only used to stay between the application and the loading form, without its the problem continues ocurring. When i kill the thread, the forms closes automaticaly, but i´ve tried to close mannualy the form in the thread, and the problems continues ocurring. I show the form as a dialog, to block the user access to the system during the process. Thanks for your time.

          ----- LeandroAB

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          LeandroABorges wrote:

          When i start the process, the form was displayed, and when the process ends, i have to close the form. Thats the reason that i habve to use a thread, because i have to continue with my process in background.

          OK. It's the long-running process that goes on the background thread, not the "Loading..." form.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          L 1 Reply Last reply
          0
          • D Dave Kreskowiak

            LeandroABorges wrote:

            When i start the process, the form was displayed, and when the process ends, i have to close the form. Thats the reason that i habve to use a thread, because i have to continue with my process in background.

            OK. It's the long-running process that goes on the background thread, not the "Loading..." form.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            L Offline
            L Offline
            LeandroABorges
            wrote on last edited by
            #5

            But how can i show the loading form, in many different process types without making a form for each process thread? If i show the form in the thread, the process will stop, because it´s a dialog. If i show the form where i call the thread, the problema is the same. How i can tell the form that the process has finished and it can close?

            ----- LeandroAB

            D 1 Reply Last reply
            0
            • L LeandroABorges

              But how can i show the loading form, in many different process types without making a form for each process thread? If i show the form in the thread, the process will stop, because it´s a dialog. If i show the form where i call the thread, the problema is the same. How i can tell the form that the process has finished and it can close?

              ----- LeandroAB

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              LeandroABorges wrote:

              But how can i show the loading form, in many different process types without making a form for each process thread?

              How about a Shared Sub? Call it whenever you launch a thread.

              LeandroABorges wrote:

              If i show the form in the thread, the process will stop, because it´s a dialog.

              No, it won't. The long-running process should be in its own thread. That will NOT hang the UI thread, so it's free to redraw itself whenever needed.

              LeandroABorges wrote:

              If i show the form where i call the thread, the problema is the same.

              No, it's not.

              LeandroABorges wrote:

              How i can tell the form that the process has finished and it can close?

              The "Loading..." form doesn't know anything about the thread process, so it'll have to be destroyed by the form that created it when you code determines that the process is complete. You might want to look into the BackgroundWorker component to help you with this.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008

              L 1 Reply Last reply
              0
              • D Dave Kreskowiak

                LeandroABorges wrote:

                But how can i show the loading form, in many different process types without making a form for each process thread?

                How about a Shared Sub? Call it whenever you launch a thread.

                LeandroABorges wrote:

                If i show the form in the thread, the process will stop, because it´s a dialog.

                No, it won't. The long-running process should be in its own thread. That will NOT hang the UI thread, so it's free to redraw itself whenever needed.

                LeandroABorges wrote:

                If i show the form where i call the thread, the problema is the same.

                No, it's not.

                LeandroABorges wrote:

                How i can tell the form that the process has finished and it can close?

                The "Loading..." form doesn't know anything about the thread process, so it'll have to be destroyed by the form that created it when you code determines that the process is complete. You might want to look into the BackgroundWorker component to help you with this.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008

                L Offline
                L Offline
                LeandroABorges
                wrote on last edited by
                #7

                Dave, Thanks for your help, i´ve decided to do somethink more simple, i´m almost out of time. I´ve disabled all the form (frm.enabled = false) and make some "Loading" label visible. Thanks for your time.

                ----- LeandroAB

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups