try/catch not working in c#, getting crazy

Started by
10 comments, last by brann 20 years ago
some new info on the problem

the problem occurs when the users hits the escape key, causing the mainloop to execute Application.Exit();
i''ve steped that in the debugger, and after this application.Exit, the program keeps executing the main loop, and in the render method, the test on device fails

i think Application.Exit() has GCed some classes, and that''s why i get nullpointerex when i try to access some variables....

but WTF.. isnt Application.Exit() supposed to free stuff, and then exit ?
Advertisement
When you call Application.Exit your form is closed, and it's DirectX device is lost, so it's best to check if the form is still valid in your rendering loop.
while(frm.Created){    frm.Render();    Application.DoEvents();}

Just close the form on an Esc keypress
protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e){    if ((int)(byte)e.KeyChar == (int)System.Windows.Forms.Keys.Escape)    this.Close();}


[edited by - Serge Asperge on March 22, 2004 12:20:32 PM]

This topic is closed to new replies.

Advertisement