Application.exit() vs Environment.exit(-1) vs Application.exitthread()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brendan Miller

    Application.exit() vs Environment.exit(-1) vs Application.exitthread()

    I am trying to close my application using Application.exi t() in the
    frmMain_Closing event. When the form closes the process does not. My
    application only has one form (no other classes either). The form has
    a really long loop which generates approx. 700 .csv files. I do not create
    any threads myself (Application.ex itthread() doesn't work either).
    To counteract this I have decided to use the Environment.exi t(-1)
    method instead.

    What is the difference between the three methods?

    Using environment.exi t() seems a strange way to do things considering there
    is a Application.exi t method which claims to do what the Environment.exi t()
    method does.
  • Jon Skeet [C# MVP]

    #2
    Re: Application.exi t() vs Environment.exi t(-1) vs Application.exi tthread()

    Brendan Miller <hovercraft2x@h otmail.com> wrote:[color=blue]
    > I am trying to close my application using Application.exi t() in the
    > frmMain_Closing event. When the form closes the process does not. My
    > application only has one form (no other classes either). The form has
    > a really long loop which generates approx. 700 .csv files. I do not create
    > any threads myself (Application.ex itthread() doesn't work either).[/color]

    Well that's the first problem - you *should* me creating a separate
    thread to do your main processing. You should test a flag in that
    thread every so often to see whether or not you should exit, and set
    that flag in your closing event.
    [color=blue]
    > To counteract this I have decided to use the Environment.exi t(-1)
    > method instead.
    >
    > What is the difference between the three methods?[/color]

    Application.Exi t is to do with message pumps - it effectively means
    that Application.Run (...) will return at that point.

    Application.Exi tThread is similar to Application.Exi t, but only for the
    message pump on the current thread.
    [color=blue]
    > Using environment.exi t() seems a strange way to do things considering there
    > is a Application.exi t method which claims to do what the Environment.exi t()
    > method does.[/color]

    No it doesn't. How is:

    <quote>
    This method stops all running message loops on all threads and closes
    all windows of the application. This method does not force the
    application to exit.
    </quote>

    the same as

    <quote>
    Terminates this process and gives the underlying operating system the
    specified exit code.
    </quote>

    ? Where is the claim you were talking about?

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...