What I have is a windows Service calling a console application that i’m running. However, when the service run it again, the console app doesn’t close. is it best to have the app close itself when it’s done running or have the service close it? In either cause can you give an example on how to close it?
while (true)
{
try
{
string ectory = @"C:\Program Files\Checker.exe";
EventLog.WriteEntry("PriceGrab", "Calling executeable");
var p = Process.Start(ectory);
if (!p.WaitForExit(30000))
{
p.Kill();
}
System.Threading.Thread.Sleep(600000); // wait 10 minutes
}
catch (Exception ex)
{
EventLog.WriteEntry("PriceGrabCall", ex.Message, EventLogEntryType.Warning);
}
This is what I have inside of my Service executable. This will not close the app. The app is designed to run once every 10 minutes. N/M works now…
It depends on the nature of the console app. If it’s like a server app and it won’t quit (has an infinite loop…), then you just start it once and only kill it when you don’t need it anymore (or just leave it running…). If it’s supposed to exit, you can give it some time to close itself, and then kill it if it didn’t finish:
But be careful when killing processes like this. You might lose the work that they were doing.