- Home /
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.
Answer by pbVax · Dec 08, 2014 at 09:02 PM
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. :)
2018, worked for me while using ffmpeg, thanks for this, saved me alot of time
Answer by Landern · Oct 23, 2014 at 03:06 PM
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.
string strCmdText = " -batch$$anonymous$$ode -quit -createProject \"" + projectPath + "\" -logFile \"" + Application.dataPath + "/createProjectLogFile.txt\" ";
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = false;
startInfo.FileName = @"C:\Program Files (x86)\Unity\Editor\Unity.exe";
startInfo.Arguments = strCmdText;
Process process = new Process();
process.EnableRaisingEvents = true;
process.Exited += new EventHandler(CreateProjectFinished);
process.StartInfo = startInfo;
process.Start();
void CreateProjectFinished(object sender, EventArgs e)
{
isProjectCreated = true;
}
Yes, i have enabled it, i am checking if isProjectFinished becomes true in Update method. But, it never becomes true.
Your answer