I have a program that executes another program and the main program continues when that program is finished.
Process p = Process.Start("program2.exe");
while (!p.HasExited)
Thread.Sleep(10000);
if (p.HasExited)
{
// Execute more code
}
This works great as when I run the program. But does not work when it is used as a scheduled task in windows. this part never executes
if (p.HasExited)
{
// Execute more code
}
Can’t seem to find a way to debug this.
I’ve been stuck on this program for a week now.
Your code would be simpler if you assume that once p.HasExited is true that it stays that way. You can then remove the if statement. Then there’s only three remaining ways I can see that your code can give the result you see:
Can you try to investigate and eliminate 1 and 2 first? It is a good idea to look at the simple alternatives first.
Update: From the comments Andrew Keith also suggested that the code might not be being executed at all. Insert log statements liberally so you can see exactly what is going on. Log to a file for example.