c# - WinForms app not closing completely -


this program class:

static class program {     private class myappcontext : applicationcontext     {         public myappcontext()         {             //exit delegate             application.applicationexit += new eventhandler(this.onapplicationexit);              //show main form             mainform main = new mainform();             main.show();         }          private void onapplicationexit(object sender, eventargs e)         {             //cleanup code...         }     }      [stathread]     static void main()     {         application.enablevisualstyles();         application.setcompatibletextrenderingdefault(false);         application.run(new myappcontext());     } } 

when i'm running app in debug mode , close it, main form closes, app still running , have click on stop debugging terminate completely.

in main form, is:

protected override void onformclosed(formclosedeventargs e) {     base.onformclosed(e);     application.exit(); } 

what doing wrong?

the problem inheriting appcontext, not sure why need that. suggest without appcontext , cleanup in mainform_closing, onformclosed, app_exit or similar event.

public class program {     [stathread]     private static void main()     {         application.enablevisualstyles();         application.setcompatibletextrenderingdefault(false);         //application.run(new myappcontext()); <- no need         application.run(new mainform());     } } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -