M
Mesan
Has anyone else noticed that even though you handle an exception that
happens within the background worker that the UnhandledException event
still fires?
For example, here's my ThreadException hookup and code :
Application.ThreadException += new
ThreadExceptionEventHandler(Application_ThreadException);
void Application_ThreadException(object sender,
ThreadExceptionEventArgs e)
{
DialogResult result = MessageBox.Show(
"Custom Error Message",
"Application Exception Reported",
MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation);
// Exits the program when the user says no.
if (result == DialogResult.No)
Application.Exit();
}
Here's my _RunWorkerCompleted() code:
private void backgroundWorker1_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show("I handled the error, why does the
ThreadException event still fire?");
}
}
So, here's the question -- why do I get both error messages?
happens within the background worker that the UnhandledException event
still fires?
For example, here's my ThreadException hookup and code :
Application.ThreadException += new
ThreadExceptionEventHandler(Application_ThreadException);
void Application_ThreadException(object sender,
ThreadExceptionEventArgs e)
{
DialogResult result = MessageBox.Show(
"Custom Error Message",
"Application Exception Reported",
MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation);
// Exits the program when the user says no.
if (result == DialogResult.No)
Application.Exit();
}
Here's my _RunWorkerCompleted() code:
private void backgroundWorker1_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show("I handled the error, why does the
ThreadException event still fire?");
}
}
So, here's the question -- why do I get both error messages?