In my console application I have code which looks like
Process DKU = new Process();
DKU.StartInfo.FileName = "MSSQLExecutor.exe";
DKU.Start();
DKU.WaitForExit();
Console.WriteLine("lets move on ");
This is working fine and it waits until MSSQLExecutor.exe finishes its job, then after that the app continues.
My problem is that sometimes MSSQLExecutor.exe crashes and Windows by default shows a dialog for ending the program. At that point my application will wait forever for the user to click the Close button.
I want to avoid this because MY application is going to run as a service without user interaction.
The Dialog prevents that the process exists.
If MSSQLExecutor
is your Application you should fix the problem.
But you can reach the goal (hiding the Dialog). Handle Application.ThreadException
and AppDomain.CurrentDomain.UnhandledException
Application.ThreadException +=new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
// log the exception
}
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
// log the exception
}
If MSSQLExecutor
is not your Application you can deactivate Dr. Watson
Dr. Watson is an application debugger included with the Microsoft Windows operating system.
This is a frequent problem running outside processes. From here I would suggest setting a maximum timeout value for this application.
Process DKU = new Process();
DKU.StartInfo.FileName = "MSSQLExecutor.exe";
DKU.Start();
DKU.WaitForExit(10*60*1000);
if (!DKU.HasExited)
DKU.Kill();
Console.WriteLine("lets move on ");
Relevent: Detecting process crash in .NET
Also, you could call Process.Kill if you only wanted to wait so long for the process to finish.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With