samsmithnz
Senior Contributor
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.
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???
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.
Code:
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???