locked
Application.Exit(); not working in the form constructor, why? RRS feed

  • Question

  • Hello,
     
    I'm using Application.Exit(); in the form contructor to terminate the application if certain condition is met... but it's not working!
     
    Why? and what can I do?
     
    Thanks...
    Wednesday, October 25, 2006 12:53 AM

Answers

  • really shouldnt be terminating the application in a constructor but in a different area/method if at all possible.

    Tried doing Environment.Exit(-1);

    doubt this would make any difference:

    Application.Exit(new CancelEventArgs(false));

    does that work? Perhaps there is something else preventing the application from exiting

    Wednesday, October 25, 2006 1:08 AM

All replies

  • really shouldnt be terminating the application in a constructor but in a different area/method if at all possible.

    Tried doing Environment.Exit(-1);

    doubt this would make any difference:

    Application.Exit(new CancelEventArgs(false));

    does that work? Perhaps there is something else preventing the application from exiting

    Wednesday, October 25, 2006 1:08 AM
  • THNAK YOU, it worked :)

    Environment.Exit(-1);

    But why it did when Application.Exit(); didn't!?

    Wednesday, October 25, 2006 2:22 AM
  • I don't know, I find that wierd.

    difference between the 2:

     

  • Application.Exit() -> informs all message pumps that they must terminate then closing all application Windows after the messages have been processed. It doesn't force the application to exit

  • Environment.Exit() -> terminates the process giving the underlying OS the error code its terminated with. You need to have the SecurityPermissionFlag.UnmanagedCode permission otherwise you will be thrown a SecurityException

Wednesday, October 25, 2006 3:00 AM