I need to perform the execution of a process for a certain time, for which I start a process, and using a Timer
after 10 minutes, I kill it using Kill()
, I do it in the following way:
using System.Diagnostics;
using System.Threading;
public class Manager{
private Process Proceso;
public Manager(){
//Inicio el proceso EdmServer
Proceso = Process.Start(@"C:\Program Files\SOLIDWORKS PDM\EdmServer.exe");
//StopProcess se ejecuta tras 10 minutos.
Timer t = new Timer(StopProcess, null, 600000 , 0);
}
private void StopProcess(object o)
{
try
{
Proceso.Kill();
}
catch(Exception ex)
{
ex.CreateLog();
}
finally
{
Environment.Exit(0);
}
}
}
The code works as I hope, the issue is that by raising the time I intend to keep the process open, increasing the wait of Timer
, when closing the process, the following exception is generated:
The request can not be processed because the process has finished.
The issue is, that goes through the finally
, the execution finishes, but the process that I intend to close is still open.
Why is the exception thrown if the process did NOT end?