Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a form that is doing some fairly hefty processing, so I display a progress bar window above it before I start the task, which has a timer on it that updates a progress bar.

 

Initially the processing was so intensitive, that the progress window never had time to update, even with application.doevents peppered through out the code.

 

So I decided to put the loading of Progress form into it's own thread. This all works fine until it's time for the progress window to close... I keep getting WindowsFormsParkingWindow errors when I'm closing the progress window, and they only happen when I enable the timer on the progress window.

 

I've googled the heck out of WindowsFormsParkingWindow and multithreaded progress windows, but it seems that no one has done anything like what I'm doing before - which I find hard to believe.

 

The code is a bit too big and sensitive to post here, but I can put in snippets.

 

   Private frmProgressi As frmProgress

   Private Sub ShowProgress()

       Try
           frmProgressi = New frmProgress

           'Show the progress window to give the user some feedback while they wait
           frmProgressi.ShowForm("Preparing Documents...")
           blnShowProgress = True

           Do While Not objActiveThread Is Nothing AndAlso blnShowProgress = True AndAlso objActiveThread.IsAlive
               Application.DoEvents()
           Loop

           'close the progress window
           frmProgressi.CloseForm()
           ''Clean up the progress just in case there are some traces of it left.
           frmProgressi.Dispose()

       Catch ex As Threading.ThreadInterruptedException
           'thread interrupted, get out of here!
           'Exit Sub
       End Try
   End Sub

   private Sub RunExpensiveFunction
                   objActiveThread = New Threading.Thread(AddressOf ShowProgress)
                   objActiveThread.Name = "Progress"
                   objActiveThread.Priority = Threading.ThreadPriority.BelowNormal ' Otherwise the progress bar eats up too much CPU time.
                   objActiveThread.Start()

                   ExpensiveFunctionIsRunHere()

                   'Clean up the progress window
                   blnShowProgress = False

   end sub

 

I've been working on this all day today and all weekend, so I'm a little frustrated. I have a couple workarounds I can try, but it seems to me that this SHOULD work... any ideas???

  • Leaders
Posted

I don't know if this will help, I don't know that much about threading but have you tried:

   private Sub RunExpensiveFunction
                   objActiveThread = New Threading.Thread(AddressOf ShowProgress)
                   objActiveThread.Name = "Progress"
                   objActiveThread.Priority = Threading.ThreadPriority.BelowNormal ' Otherwise the progress bar eats up too much CPU time.
                   objActiveThread.Start()

                   ExpensiveFunctionIsRunHere()


                   'Clean up the progress window
                   blnShowProgress = False
                   objActiveThread.Join() '<--Wait for the other thread to finish
   end sub

[sIGPIC]e[/sIGPIC]
Posted

Well I worked this out... I reversed the threading so that the progress popup window was part of the main thread, and my new processing thread was for the expensive function...

 

Now to do the same with web services... Asynchronous web services should be fun... right? ;)

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...