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:
ProcessStartInf o psi = new
ProcessStartInf o("CMD.EXE",que ry);
psi.UseShellExe cute = useShellExec;
psi.RedirectSta ndardOutput = stdout;
psi.CreateNoWin dow = noWindow;
hbProc = new Process();
hbProc = Process.Start(p si);
hbProc.WaitForE xit();
Thanks,
Alistair. 4 8541
Well, you could use:
while(!hbProc.W aitForExit(some Timeout)) {
if(ShouldCancel ) break;
}
Marc
On Sep 19, 5:15 am, "Marc Gravell" <marc.grav...@g mail.comwrote:
Well, you could use:
while(!hbProc.W aitForExit(some Timeout)) {
if(ShouldCancel ) break;
}
Marc
(note, there is no reason to call both the new Process() and the
Process.Start(p si);
Or you could use:
hbProc = new Process();
hbProc.EnableRa isingEvents = true;
hbProc.Exited += new EventHandler(fu nctionToCallAft erProcessExit);
hbProc.StartInf o = psi;
hbProc.Start();
// other thread - on want to cancel event:
hbProc -= new EventHandler(fu nctionToCallAft erProcessExit);
In either case, just be aware of the potential race condition between
the process exiting and the desire to cancel the wait...
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:
ProcessStartInf o psi = new
ProcessStartInf o("CMD.EXE",que ry);
psi.UseShellExe cute = useShellExec;
psi.RedirectSta ndardOutput = stdout;
psi.CreateNoWin dow = noWindow;
hbProc = new Process();
hbProc = Process.Start(p si);
hbProc.WaitForE xit();
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).
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 WaitForExit(). The first process
basically launch a DOS batch file to do some task, am I missing anything?
executable = "setup_listener.bat";
process1 = new Process();
process1.StartInfo.UseShellExecute = false;
process1.StartInfo.CreateNoWindow =...
|
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 this object." Is it just finishing
before I make the call? The process seems to finish (I have a compiled and
working help.chm).
If set StartInfo.UseShellExecute = false; I get a
System.ComponentModel.Win32Exception ("%1 is not a valid Win32...
|
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 process already ended and with what
exitcode it has finished.
|
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 myProcess As Process = _
System.Diagnostics.Process.Start("notepad.exe")
' wait until it exits
myProcess.WaitForExit()
|
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, the app exits but
then the command window opens and the process runs on its own. Could
the "WaitForExit" call be happening too soon?
Private Sub ZipDirs(ByVal PCName As String)
Dim WinZip As New System.Diagnostics.Process
Dim args As String = "...
| |
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 checking the ExitCode
and it can't do that. It just freezes on WaitForExit. How can I get
objProcess.WaitForExit to work in a service application? Thanks.
|
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 WaitForExit methos with a
timeout.
So in order to test this, I added an endless loop to the other program such
that it never returns. My problem is that neither does WaitForExit. Even
WaitForExit( 1 ) never returns when the other program hangs.
|
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 Reference in the start menu is the only
way to access it.
I have the following code used to start the other program:
|
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 windows service that converts MS Word Files into .PDF files and after that we want to zip the .PDF files.
Our code:
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |