473,508 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Process.WaitForExit Question

77 New Member
I have written a windows application that kicks off another process and then Waitsforexit. I have one old crappy machine on which this works great and has been for months and in the last couple of months I've seen that on a newer faster machine that it doesn't seem to work reliably. Both are XP SP3 and the app utilizes Framework 2.0. Any ideas?

Expand|Select|Wrap|Line Numbers
  1. ProcessStartInto ps=new ProcessStartInfo();
  2. ps.FileName=sFilename;
  3. ps.Arguments=sArguments;
  4. ps.WorkingDirectory=sWorkingDirectory;
  5. p.EnableRaisingEvents=true;
  6.  
  7. p=Process.Start(ps);
  8. try
  9. {
  10. p.WaitForExit();
  11. TaskStopped(p);
  12. p.Close();
  13. }
  14. catch (Exception ex)
  15. {
  16. //Log Error Message only
  17. }
Nov 10 '09 #1
9 8381
Plater
7,872 Recognized Expert Expert
What do you mean doesn't work reliably?
Is the process starting and ending faster then you can follow on the newer machine perhaps?
Nov 10 '09 #2
stoogots2
77 New Member
Thanks for the response Plater. The process usually takes about 90 minutes to complete but another thread checks every minute to make sure it takes no longer than 180 minutes or it kills it. I saw in the log that the process got killed after 180 minutes although the output that was expected from the process was completed in the normal timeframe. I've seen this more than once, but only on this one computer. I have 3 other computers running the same code without ever having experienced this problem.
Nov 10 '09 #3
Plater
7,872 Recognized Expert Expert
So its not the waitforexit() that's failing, its that the process is never exiting.
Nov 10 '09 #4
stoogots2
77 New Member
I have every indication that the process is exiting except that I do not see the WaitForExit completing and the paused thread continuing. The output of the process is there and in all other cases where this code is executing, the process has exited. There shouldn't be anything different about the 5th machine running the same application/framework/operating system/service pack.
Nov 11 '09 #5
Plater
7,872 Recognized Expert Expert
I thought you said you had a seperate thread that is checking to make sure the processes ended and kills it if it didn't. If you can still see the process in that thread, it had never ended
Nov 11 '09 #6
stoogots2
77 New Member
The main thread just waits a configurable amount of time and Process.Kills the worker thread if it doesn't proceed past p.WaitForExit().
Nov 11 '09 #7
Plater
7,872 Recognized Expert Expert
Hmm is there any reason it NEEDS to wait for exit? If it just gets killed off anyway?
Nov 11 '09 #8
stoogots2
77 New Member
Yes, there is a need for it to waitforexit. It only gets killed off if there is not a problem, so in most cases it won't get killed. I kill the process only when it has run for twice the "normal" completion period without completing. The problem is that if there isn't a problem, it doesn't seem to return from WaitForExit every time. I have 3 other instances of the same program running and returning from WaitForExit every time. It is just strange that the new computers don't return each and every time.
Nov 11 '09 #9
GaryTexmo
1,501 Recognized Expert Top Contributor
Out of curiosity, have you tried using the event handler on the process object? I'm not saying you should use it instead, I'm just curious of the callback works for you, whereas the waitforexit seems to be behaving oddly.

Expand|Select|Wrap|Line Numbers
  1.                 Process myProcess = new Process();
  2.                 myProcess.StartInfo.FileName = ...;
  3.                 myProcess.StartInfo.Arguments = ...;
  4.                 myProcess.EnableRaisingEvents = true;
  5.                 myProcess.Exited += new EventHandler(mergeToolProcess_Exited);
  6.  
  7.                 myProcess.Start();
Nov 12 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
22485
by: James Li | last post by:
I have the code below, the first process takes about 10 minutes to finish. But the waitForExit doesn't seem to wait when I debug the program, it go immediately to execute code after the...
10
15894
by: Tony | last post by:
I am running an application called AcroComm.exe to poll time clocks here at our company. I have written a small C# app that will poll the clocks based on information found in a DB. My problem is...
4
3989
by: Christian Billig | last post by:
Hi, well i've a problem and i don't know how to solve it. I wrote a function, which starts a Process for a user by using the API CreateProcessWithLogon. Afterwards i want to know if the...
6
1947
by: jcrouse | last post by:
This is kind of a continuation of another thread that was somewhat resolved: Well, the dilemma seems to be this. I want to be able to hide the DOS box AND pause the code until execution is...
2
18332
by: Terry Olsen | last post by:
Using the following code, I get the error "No process is associated with this object" when calling the WinZip.WaitForExit() method. After I click the "Break" or "Continue" button on the dialog,...
7
7298
by: Bob | last post by:
Process.start("Mydoc.doc") starts Word with the file. I need to wait for Word to be closed before more code can execute in my app. How can I do this? Thanks for any help Bob
1
8381
by: Chris | last post by:
Hello, I have a Windows Forms application which has buttons to click to run other programs. One of the applications it must run is a ClickOnce Windows Forms application, so the Application...
9
18846
by: Eran.Yasso | last post by:
Hi, My app starts process. Some times this process exits because of exception. Can my app know if the process exited due to exception or gracefully? In both ways, the exit code of this...
5
5066
by: andrew | last post by:
Hi, I have the following issue with the Thread.Abort(): The main thread creates a worker thread which waits on a process termination. void ThreadProc() { Process proc =...
4
8793
by: Steven De Smet | last post by:
Hello, This is my first post. I searched on the internet for answers but I was unable to solve my problem. So I hope that you guy's can help me with my VB.NET problem I tried to create a...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.