Dot Net: How pass ExitCode from created proces back to parent?

Posted on 2009-02-24
Last Modified: 2013-12-17
Kinda stuck here--how pass ExitCode from "forked" forms-based dot-net application back to parent?

1 You cannot pass an integer to Application.Exit() !!!  seems to be an oversight to me!

2 Application.ExitCode property does not exist!

3 ApplicationExit event method returns void... another oversight?

I want to shut down the child process "properly"... release memory, etc., so Environment.Exit may not be appropriate?
Parent process:

System.Diagnostics.Process p = System.Diagnostics.Process.Start(@"MyProgram.exe", s);


int exitCode = p.ExitCode;

Console.WriteLine("Exited ExitCode=" + exitCode);

Child process:


Application.Exit(1);  //NOT!!!


void Application_ApplicationExit(object sender, EventArgs e) {

    // set ExitCode here???


Open in new window

Question by:ZuZuPetals
    LVL 22

    Accepted Solution

    Instead of Application.Exit, use Environment.Exit, that allows you to set the exit code, but there are some unmanaged code permissions you have to have:
    LVL 22

    Expert Comment

    Sorry, just read the part about Environment.Exit may not be appropriate
    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    Use Environment.ExitCode:

        "If the Main method returns void, you can use this property to set the exit code that will be returned to the calling environment."

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Flash ( has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now