• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

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

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

  • 2
2 Solutions
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:

Sorry, just read the part about Environment.Exit may not be appropriate
Mike TomlinsonMiddle School Assistant TeacherCommented:
Use Environment.ExitCode: http://msdn.microsoft.com/en-us/library/system.environment.exitcode.aspx

    "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

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now