Ldg
Ldg

Reputation: 261

I get "has stopped working" error when I use 'Application.Exit();' in C#

In my application I launch several processes, and when I use the command Aplication.Exit(); Windows gives me the "has stopped working" error. I don't understand why, also the Enviroment.Exit(0); give me this error.

I use the Awesomium webcontrol, and before launch Application.Exit(); I call

WebCore.Shutdown();

and then

Process.Start("cmd.exe", "/c " + @"rmdir /s/q " + dir); // erase all temporary files

Application.Exit();

Upvotes: 0

Views: 1119

Answers (1)

Steven Magana-Zook
Steven Magana-Zook

Reputation: 2759

Try this, it will wait for the process to end before exiting the application:

// erase all temporary files    
Process process = Process.Start(@"rmdir /s/q " + dir); 
process.WaitForExit();

Application.Exit();

If this does not work, put a breakpoint on the process.WaitForExit() line and try to get a StackTrace / exception message to help us figure out what is going wrong.

Upvotes: 2

Related Questions