Hi Andrea,
Yes, starting from .Net2.0, the unhandled exception generated in worker
thread will also crash the AppDomain, while .Net1.1 CLR will just swallow
it. In this scenario, you have 2 options:
1. Use a big try...catch around all threads procedure, so that you can
catch any unhandled exceptions. Then, you may use EventLog or some other
approaches to log the exception details and terminate the proces with
Application.Exi t.(It is recommended that you terminate the process)
2. You may leverage the AppDomain.Unhan dledException event to monitor the
unhandled exceptions in the AppDomain and log it. There is no need for you
to terminate the process in this scenario, because
AppDomain.Unhan dledException is merely a notification event, CLR will
always terminate the AppDomain. Below sample code snippet demonstrates the
logic:
void ThreadProc()
{
throw new Exception("abc" );
}
private void button1_Click(o bject sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(Thr eadProc));
t.Start();
}
private void Form1_Load(obje ct sender, EventArgs e)
{
AppDomain.Curre ntDomain.Unhand ledException += new
UnhandledExcept ionEventHandler (CurrentDomain_ UnhandledExcept ion);
}
void CurrentDomain_U nhandledExcepti on(object sender,
UnhandledExcept ionEventArgs e)
{
Exception except = e.ExceptionObje ct as Exception;
MessageBox.Show ("Applicatio n is crashing with Stack Trace below:\n"+
except.StackTra ce);
}
Additionally, Jason Clark written a good article talking about the
unhandled exceptions in .Net1.1. Although, this article only talks about
.Net1.1, much of the information is still valuable for .Net2.0:
"Unexpected Errors in Managed Applications"
http://msdn.microsoft.com/msdnmag/is...T/default.aspx
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day 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 or complex
project analysis and dump analysis issues. 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/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.