Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,

I got a running service that starts process (exe file with some parameters), when requests comes. That process is start with Process.Start. After executing Start() I am firing new thread that tries to attach to that started process by ID and sets an event when that process ends. ShellExecute is set to true.
C#
runnerProc.Exited += ProcessEnded;

Now - everything works fine until some moment when I get lots of requests and many process are being started at almost the same time. Most of them are ok, but some hang. Meaning that new thread is started, it finds the process by id which is alive and sets the ending event for that process - this thread will be alive until the process is done running. But the problem is that the new process start with an error (not Application, but System type!!). In System logs I see this:"
C#
Application popup: Runner.exe - Application Error : The application was unable to start correctly (0xc0000142). Click OK to close the application. 

Now - it looks like my thread has started and attached to process, but since the process did not close - it thinks that it's running infinitely. What is more odd - when I check the task manager - such process with that ID is not running any more oddly somewhy the exit event was not called...

I was thinking if this is somehow related to ShellExecute set to True, but not really sure. All code has error handling so if anything goes wrong I get log about the process not being able to start. So in my case - I get no errors and RunnerProc.Exited gets event assigned properly - it just not getting called 1 out of ~50.

Any ideas what am I doing wrong?
Thanks!

What I have tried:

Tried various things here... kind of out of ideas now
Posted
Updated 22-Oct-16 21:16pm
v2
Comments
Dave Kreskowiak 23-Oct-16 9:47am    
You never posted the code that you're using. It sounds like you're spawning a new thread at the wrong time, after you're launching the process. You would normally spawn a new thread and the that thread sets up the process object AND the exited event handler BEFORE you start the process.
Suvabrata Roy 26-Oct-16 6:05am    
Please post your code it will help us to analyze the issue

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900