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
Post a Comment