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. Threading

Threading

Scheduled Pinned Locked Moved Visual Basic
questionhelptutorial
2 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.
  • C Offline
    C Offline
    Cory Kimble
    wrote on last edited by
    #1

    I am having trouble getting my head around a Threading problem I have. I want to process some data while displaying a message stating that the data is being processed. So hear is some sample code that I have been trying.

    thrd = New Thread(AddressOf ThreadProc)

    thrd.start()

    'process data

    thrd.abort 'I want a way to know when process data is done.

    Private Sub ThreadProc()

        Dim load As New Loading
    
        load.ShowDialog()
        
    End Sub
    

    But, When my process is done the showdialog does not go away until I click in the form or move the mouse. Any suggestions on how to do this. How can I get the showdialog to go away?

    L 1 Reply Last reply
    0
    • C Cory Kimble

      I am having trouble getting my head around a Threading problem I have. I want to process some data while displaying a message stating that the data is being processed. So hear is some sample code that I have been trying.

      thrd = New Thread(AddressOf ThreadProc)

      thrd.start()

      'process data

      thrd.abort 'I want a way to know when process data is done.

      Private Sub ThreadProc()

          Dim load As New Loading
      
          load.ShowDialog()
          
      End Sub
      

      But, When my process is done the showdialog does not go away until I click in the form or move the mouse. Any suggestions on how to do this. How can I get the showdialog to go away?

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi Cory, this is so wrong. It is almost always a bad idea to abort a thread since you typically don't know what it is doing at that specific point in time, and resources may be locked, memory allocated, etc. In this particular case, aborting the thread stops the message pump that was keeping the progress dialog alive (the pump is a loop running inside the ShowDialog method); by aborting the thread, the dialog just sits there, completely dead, what piece of code would be responsible of removing it? The correct way to handle this is by: 1. putting the time-consuming stuff in a thread or a BackgroundWorker (BGW are available since .NET 2.0), which you want to run to completion, hence no abort necessary; 2. showing the progress dialog in the normal manner, without using an extra thread. 3. letting the thread/BGW signal the progress dialog when it is done (this obviously requires caution about cross-thread violations, automatically solved by BGW, and solvable with Control.InvokeRequired/Control.Invoke on regular threads. 4. you may add real progress indication in the dialog; again a BGW is helping there 5. you may want to add a Cancel button; the proper way to handle a cancel request is by having the background job done in a collaborative way, typically by periodically checking a "please cancel" flag. Don't use Thread.Abort if you don't have to! I strongly suggest you study some BackgroundWorker examples. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


      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