473,505 Members | 13,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WaitForExit();

How permanent is WaitForExit(); ? I mean is there anything/ an
alternative one can do to break the wait otherwise I will run my thread
in a separate function, and control it by global variables.
Reason - a CMD.EXE thread, with a console application running, which we
need to cancel out of prior to the thread running its course.
Here is what we have:
ProcessStartInfo psi = new
ProcessStartInfo("CMD.EXE",query);
psi.UseShellExecute = useShellExec;
psi.RedirectStandardOutput = stdout;
psi.CreateNoWindow = noWindow;
hbProc = new Process();
hbProc = Process.Start(psi);
hbProc.WaitForExit();
Thanks,
Alistair.
Sep 19 '07 #1
4 8535
Well, you could use:

while(!hbProc.WaitForExit(someTimeout)) {
if(ShouldCancel) break;
}

Marc
Sep 19 '07 #2
On Sep 19, 5:15 am, "Marc Gravell" <marc.grav...@gmail.comwrote:
Well, you could use:

while(!hbProc.WaitForExit(someTimeout)) {
if(ShouldCancel) break;

}

Marc
(note, there is no reason to call both the new Process() and the
Process.Start(psi);

Or you could use:

hbProc = new Process();
hbProc.EnableRaisingEvents = true;
hbProc.Exited += new EventHandler(functionToCallAfterProcessExit);
hbProc.StartInfo = psi;
hbProc.Start();
// other thread - on want to cancel event:
hbProc -= new EventHandler(functionToCallAfterProcessExit);

In either case, just be aware of the potential race condition between
the process exiting and the desire to cancel the wait...

Sep 19 '07 #3
On Sep 19, 4:11 am, Alistair George <non...@xtra.co.nzwrote:
How permanent is WaitForExit(); ? I mean is there anything/ an
alternative one can do to break the wait otherwise I will run my thread
in a separate function, and control it by global variables.
Reason - a CMD.EXE thread, with a console application running, which we
need to cancel out of prior to the thread running its course.
Here is what we have:
ProcessStartInfo psi = new
ProcessStartInfo("CMD.EXE",query);
psi.UseShellExecute = useShellExec;
psi.RedirectStandardOutput = stdout;
psi.CreateNoWindow = noWindow;
hbProc = new Process();
hbProc = Process.Start(psi);
hbProc.WaitForExit();

Thanks,
Alistair.
You can either kill the thread running WaitForExit() or use the
overload that allows you to specify a timeout bool WaitForExit(int
msToWait). If you run it in a separate thread and kill it you're
going to get an interrupted exception. You may want to make sure the
process you started isn't still running (if it is, kill it).

Sep 19 '07 #4
You can either kill the thread running WaitForExit() or use the
overload that allows you to specify a timeout bool WaitForExit(int
msToWait). If you run it in a separate thread and kill it you're
going to get an interrupted exception. You may want to make sure the
process you started isn't still running (if it is, kill it).
Thanks guys with the suggestions which are useful. Will advise what
option worked best.
Al.
Sep 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
22484
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...
1
5251
by: PaulFir509 | last post by:
I am attempting to run the HTML help compiler from within another application. When I get to the WaitForExit call, I get a System.InvaidOperationException and a message "No process associated with...
4
3987
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...
4
2541
by: Terry Brown | last post by:
I am trying to use WaitForExit to determine when an external application I have launched has exited (duh!). I found examples everywhere and it seemed simple and this works perfectly: Dim...
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,...
0
1498
by: Phil Galey | last post by:
In VB.NET, does the Process object not work fully from within a service application. It seems to be able to run the external .exe that it's supposed to run, but I do a WaitForExit followed by...
1
3084
by: Ebbe Kristensen | last post by:
Hi All I am writing a C# program that starts another program. Since this is destined to run on an un-attended PC, I want to be certain that my program can regain control. To this end, I use the...
1
8371
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...
4
8792
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
7098
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
7298
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,...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
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
3187
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
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1526
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
754
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.