I use this code to catch a WinForm UnhandledException application.
[STAThread]
static void Main(string[] args)
{
Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
try
{
Application.Run(new MainForm());
} catch....
There I will try to restart the application. Now my problem is to simulate an exception like this. I tried before trying (mostly): throw new NullReferenceException("test");VS caught it.
I also tried in the MainForm code with a button:
private void button1_Click(object sender, EventArgs ev)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(TestMe), null);
}
protected void TestMe(object state)
{
string s = state.ToString();
}
didn't help, VS caught it, even in Release mode.
- How should I finally get the application to generate ?
UnhandleldException - Will I be able to restart the application in
CurrentDomain_UnhandledException? - How can i create ?
ThreadException
PS.
If I run out VS window with a common window
MyApplication application "encountered an error and needs to close ... blabla ... Send Report / Do Not Send.
I want, however, VS introduce this method (... Domain_Unhahdled ...)
EDIT:
Windows, :
alt text http://byfiles.storage.msn.com/y1pOhWnAAXfMYtJH2VNa5iL0l1hjAqNHD2VmVnl8nN6L1oQC_xHkyHCJxhMc1ZLxLOH9ZXfZoo5zX8?PARTNER=WRITER
:
static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)
{
Logger.LogMessage(ERROR, errorMsg);
Application.Restart();