Re: BackgroungWork taske ended for no appearent reason
- From: Stewart Berman <saberman@xxxxxxxxxxxxx>
- Date: Mon, 20 Jul 2009 11:05:19 -0400
So at this point my suggestion is to use a Try...Catch in your DoWork event
handler so you can handle the exceptions gracefully and preventing the work
being interrupted.
I keep adding Try/Catch blocks all over the place. Since all of the errors I have trapped so far
are do to a file being temporarily locked I need the equivalent of the old:
On Error GoTo lblError
<snip>
lblError:
select case err.ErrorNumber
case <file locked>
sleep (1000)
resume
case
case
case else
err.raise ...
end select
To do the same thing with Try/Catch blocks requires wrapping every file access with a Do While ...
Loop with a Try/Catch block in it -- which I effectively did for the trace statements.
What is the best way to handle the cleanup and restart of the BackgroundWorker task?
I can raise an event in the OnRunWorkerCompleted method that can be handled in the main GUI thread.
However, I cannot dispose of the class that wraps the BackgroundWorker class since the event will
return to code in that class. It appears that I would have to kick off a timer whose event would
call the BackgroundWorker's wrapper's class's Dispose() method, set the wrapper class to nothing and
then instantiate the wrapper class again.
There has to be a cleaner way to handle this.
jiewan@xxxxxxxxxxxxxxxxxxxx ("Jie Wang [MSFT]") wrote:
Hi Stewart,.
If there was any exception thrown in your DoWork event handler, and you
didn't handle it, then what you have seen is just expected.
Refering to the document of this event on how it works with unhandled
exceptions:
If the operation raises an exception that your code does not handle, the
BackgroundWorker catches the exception and passes it into the
RunWorkerCompleted event handler, where it is exposed as the Error property
of System.ComponentModel.RunWorkerCompletedEventArgs. If you are running
under the Visual Studio debugger, the debugger will break at the point in
the DoWork event handler where the unhandled exception was raised.
Read the Remarks section in the following link:
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundwork
er.dowork(VS.80).aspx
So at this point my suggestion is to use a Try...Catch in your DoWork event
handler so you can handle the exceptions gracefully and preventing the work
being interrupted.
Regards,
Jie Wang
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
- References:
- BackgroungWork taske ended for no appearent reason
- From: Stewart Berman
- RE: BackgroungWork taske ended for no appearent reason
- From: "Jie Wang [MSFT]"
- BackgroungWork taske ended for no appearent reason
- Prev by Date: Re: mscomm & richtext on VB.NET 2008
- Next by Date: Visual Basic 2008 Express "Exclude From Project" ...
- Previous by thread: RE: BackgroungWork taske ended for no appearent reason
- Next by thread: Re: BackgroungWork taske ended for no appearent reason
- Index(es):
Relevant Pages
|
Loading