T
Tim_Mac
hi,
i've used jason clarks recommendations for handling unhandled
exceptions in my winforms app
(http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx).
if an unhandled exception happens, i open up an 'Error-Logger' form,
which sends the exception to a web service. here is the relevant code:
[STAThread]
public static void Main()
{
try
{
SubMain();
}
catch (Exception e)
{
HandleUnhandledException(e);
}
}
public static void SubMain()
{
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(OnUnhandledException); // CLR
Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(OnGuiUnhandedException); //
Windows Forms
Application.Run(new MainForm());
}
public static void HandleUnhandledException(Object o)
{
if(o == null)
{
MessageBox.Show("An unknown error has occurred", "Error");
return;
}
Exception ex = o as Exception;
if (ex != null)
new ErrorLogger(ex).ShowDialog();
}
this approach works very well. the problem of a dangling process
occurs if the user closes the ErrorLogger form before it has finished
reporting the error. A ThreadAbortException happens (which i catch and
ignore) in ErrorLogger, and the error logger form closes. if i then
close the mainform, the process is left dangling in task manager with
no windows open.
this only happens if the user kills the errorlogger form. the
errorLogger form calls the web service on a worker thread, but i am
careful to Abort this thread in Dispose() and Form.Close() and even
when the ThreadAbortException happens.
is there any way for me to work around this? maybe the application is
creating two UI threads because ShowDialog is called twice, and only
one of those threads gets properly terminated when the application is
closed?
thanks for any help
tim
i've used jason clarks recommendations for handling unhandled
exceptions in my winforms app
(http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx).
if an unhandled exception happens, i open up an 'Error-Logger' form,
which sends the exception to a web service. here is the relevant code:
[STAThread]
public static void Main()
{
try
{
SubMain();
}
catch (Exception e)
{
HandleUnhandledException(e);
}
}
public static void SubMain()
{
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(OnUnhandledException); // CLR
Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(OnGuiUnhandedException); //
Windows Forms
Application.Run(new MainForm());
}
public static void HandleUnhandledException(Object o)
{
if(o == null)
{
MessageBox.Show("An unknown error has occurred", "Error");
return;
}
Exception ex = o as Exception;
if (ex != null)
new ErrorLogger(ex).ShowDialog();
}
this approach works very well. the problem of a dangling process
occurs if the user closes the ErrorLogger form before it has finished
reporting the error. A ThreadAbortException happens (which i catch and
ignore) in ErrorLogger, and the error logger form closes. if i then
close the mainform, the process is left dangling in task manager with
no windows open.
this only happens if the user kills the errorlogger form. the
errorLogger form calls the web service on a worker thread, but i am
careful to Abort this thread in Dispose() and Form.Close() and even
when the ThreadAbortException happens.
is there any way for me to work around this? maybe the application is
creating two UI threads because ShowDialog is called twice, and only
one of those threads gets properly terminated when the application is
closed?
thanks for any help
tim