samsmithnz Posted April 4, 2005 Posted April 4, 2005 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??? Quote Thanks Sam http://www.samsmith.co.nz
Leaders snarfblam Posted April 4, 2005 Leaders Posted April 4, 2005 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 Quote [sIGPIC]e[/sIGPIC]
samsmithnz Posted April 5, 2005 Author Posted April 5, 2005 Unfortunetly that doesn't help. I think I need to raise some sort of event or something to stop the timer before I stop the thread... Quote Thanks Sam http://www.samsmith.co.nz
samsmithnz Posted April 6, 2005 Author Posted April 6, 2005 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? ;) Quote Thanks Sam http://www.samsmith.co.nz
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.