D
ditnooitlezen
Hi,
the (.NET 2.0) backgroundworker object has a DoWork method that
operates in a background thread. When the DoWork method is finished the
RunWorkerCompleted event is raised in the parent thread.
Now I have in the backgroundworker's DoWork method a try catch finally
block, like this:
StreamReader sr = null;
try
{
sr = new StreamReader("blahdieblah" +
e.Argument.ToString());
if (!this.CancellationPending)
try
{
e.Result = sr.ReadToEnd();
}
catch (Exception exc)
{
throw exc;
}
else
{
e.Cancel = true;
e.Result = null;
}
}
catch (Exception exc)
{
throw exc;
}
finally
{
if (sr != null) sr.Close();
}
return;
The "blahdieblah" part is to force an error. The 'e' is een event
argument that is passed to the DoWork method.
The error is catched, but code execution always breaks at the 'throw
exc' line.
I presumed that the error should have been propagated to the
RunWorkerCompletedEventArgs, in it's .Error property. However it never
gets there.
What did I miss? When and how will the .Error property be filled and
RunWorkerCompleted called, like the documentation states.
the (.NET 2.0) backgroundworker object has a DoWork method that
operates in a background thread. When the DoWork method is finished the
RunWorkerCompleted event is raised in the parent thread.
Now I have in the backgroundworker's DoWork method a try catch finally
block, like this:
StreamReader sr = null;
try
{
sr = new StreamReader("blahdieblah" +
e.Argument.ToString());
if (!this.CancellationPending)
try
{
e.Result = sr.ReadToEnd();
}
catch (Exception exc)
{
throw exc;
}
else
{
e.Cancel = true;
e.Result = null;
}
}
catch (Exception exc)
{
throw exc;
}
finally
{
if (sr != null) sr.Close();
}
return;
The "blahdieblah" part is to force an error. The 'e' is een event
argument that is passed to the DoWork method.
The error is catched, but code execution always breaks at the 'throw
exc' line.
I presumed that the error should have been propagated to the
RunWorkerCompletedEventArgs, in it's .Error property. However it never
gets there.
What did I miss? When and how will the .Error property be filled and
RunWorkerCompleted called, like the documentation states.