System.Diagnostics.Process.Exited not firing in executable

Hi, i am using system.diagnostics.process to create and start a unity project in batchmode. I have everything working great. I am calling unity.exe in process with some arguments like, -batchMode, -quit, and -logFile. When i start app in unity editor, process creates a project, then process.Exited fires, then another process puts some files and starts the project in batchMode.

My problem is that when i build this app, and start its executable, the process again creates the project however it does not fires exited event, eventually other steps wont begin due to first process not firing exited event. I do not know why System.Diagnostics.Process.Exited is not firing when builded. I could not find any solution, so i am asking the reason for it in here.

I just encountered this problem myself, and discovered a solution: In your “Build Settings”, under the “Other Settings” section, set your “Api Compatibility Level” to “.NET 2.0”.

My guess is that Unity Editor is uses .NET 2.0 when you run your program, but when you execute your program separately, the “.NET 2.0 Subnet” doesn’t support the Exited functionality.

I suspect this solution will work only under Windows. :slight_smile:

Not sharing the Process object instantiation isn’t helping.

Have you set EnableRaisingEvents on the Process object to true? If it is not set, it will not raise the Exited event amongst others.