Re: BackgroungWork taske ended for no appearent reason



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



Relevant Pages

  • RE: VB Compiler Error in VS2005 Team Dev
    ... Then I got an unhandled exception in the ... In the details information from the Microsoft Application Error Reporting ... debug and went to add an event handler for the datagridview dataerror ... Microsoft Online Community Support ...
    (microsoft.public.vsnet.debugging)
  • RE: VB Compiler Error in VS2005 Team Dev
    ... Then I got an unhandled exception in the ... In the details information from the Microsoft Application Error Reporting ... debug and went to add an event handler for the datagridview dataerror ... Microsoft Online Community Support ...
    (microsoft.public.vsnet.debugging)
  • RE: JIT debugging not being activated
    ... exception handler in the top of its message loop. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.vsnet.debugging)
  • Re: Trapping Exceptions - another issue
    ... I'd like to say that the behaviors of the exception handling are ... Application.ThreadException event handler is hooked up, ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Trapping Exceptions - another issue
    ... I'd like to say that the behaviors of the exception handling are ... Application.ThreadException event handler is hooked up, ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.windowsforms)

Loading