FLX 11
New Member
Hello all,
I have problems letting this application wait. I tried everything in my knowledge.
Here is the code: -
System.Diagnostics.Process procdemux = new System.Diagnostics.Process();
-
procdemux.StartInfo.UseShellExecute = true;
-
procdemux.StartInfo.CreateNoWindow = false;
-
procdemux.StartInfo.RedirectStandardOutput = false;
-
procdemux.StartInfo.FileName = currentPath + "\\res\\demux.bat";
-
procdemux.Start();
-
procdemux.WaitForExit(3000);
-
procdemux.Close();
-
this code follows it up: -
System.Diagnostics.Process procencode = new System.Diagnostics.Process();
-
procencode.StartInfo.UseShellExecute = true;
-
procencode.StartInfo.CreateNoWindow = false;
-
procencode.StartInfo.RedirectStandardOutput = false;
-
procencode.StartInfo.FileName = currentPath + "\\res\\encode.bat";
-
procencode.Start();
-
procencode.WaitForExit(3000);
-
procencode.Close();
-
Can someone please help me?
Thanks in advance!
Regards,
Dennis
12 1444 FLX 11
New Member
please, someone?
Regards,
Dennis
Hello, I do not know this way, but I learn another way to stop your app: -
//Stop your app for 1000 milliseconds.
-
System.Threading.Thread.Sleep(1000);
-
This code will stop your app for 1 sec.
--------------------------------------------------------
But If you mean to wait for load something, I do not know.
"TRScheel" user help me with the code I give you.
Hope this help you.
Hello, I do not know this way, but I learn another way to stop your app: -
//Stop your app for 1000 milliseconds.
-
System.Threading.Thread.Sleep(1000);
-
This code will stop your app for 1 sec.
--------------------------------------------------------
But If you mean to wait for load something, I do not know.
"TRScheel" user help me with the code I give you.
Hope this help you.
If you don't supply a time for the WaitForExit() call it will wait for as long as it takes the application to exit. Could you try explaining your problem a little bit better? I'm not sure I get what your asking.
-mwalts
Plater 7,872
Recognized Expert Expert
You're currently only waiting 3 seconds before you are manually closing that process. Seems a bit quick?
I have a similar problem. I want to run an external app for 20 seconds and then to close.
i am using waitforexit(200 00) but it isn't working.
can u tell me how to close an application after 20 seconds ???
pls help me
private void button2_Click(o bject sender, EventArgs e)
{
System.Diagnost ics.Process p = new System.Diagnost ics.Process();
p.StartInfo.Fil eName = @"calc.exe";
p.Start();
p.WaitForExit(2 0000);
}
I have a similar problem. I want to run an external app for 20 seconds and then to close.
i am using waitforexit(200 00) but it isn't working.
can u tell me how to close an application after 20 seconds ???
pls help me
private void button2_Click(o bject sender, EventArgs e)
{
System.Diagnost ics.Process p = new System.Diagnost ics.Process();
p.StartInfo.Fil eName = @"calc.exe";
p.Start();
p.WaitForExit(2 0000);
}
This doesn't seem a good approach to me. In Win32 programming we had the WaitForSingleOb ject method, but in .NET....I don't know...yet.
If the application you're starting is also written by you, then you could create a small protocol using a semaphore file:
- create a semaphore file
- call the second app
- in the second app, before closing delete the semaphore file
- meanwhile in the main .NET app, check for the existence of the semaphore file every 500 ms or so:
while(File.Exis ts("sem.txt"))
{
Thread.Sleep(50 0);
}
This doesn't seem a good approach to me. In Win32 programming we had the WaitForSingleOb ject method, but in .NET....I don't know...yet.
If the application you're starting is also written by you, then you could create a small protocol using a semaphore file:
- create a semaphore file
- call the second app
- in the second app, before closing delete the semaphore file
- meanwhile in the main .NET app, check for the existence of the semaphore file every 500 ms or so:
while(File.Exis ts("sem.txt"))
{
Thread.Sleep(50 0);
}
The application I want to terminate after the 20 seconds is SerialMagic, so I don't have access to the code.
Plater 7,872
Recognized Expert Expert
Try this program flow:
Start your external application (using Process)
Tell the current application to wait (Thread.Current Thread.Sleep()? ) the desired time
Kill the external program (using the Process object from earlier)
I am not sure what your problem with the initial code was.
An external program was started
It was given 3seconds of time to open and run before you closed it
TRScheel 638
Recognized Expert Contributor
Why havent I seen this thread earlier?
Anyways, this will be useful to you: -
private static bool CheckProcess(Process process)
-
{
-
bool processFinished = true;
-
try
-
{
-
process.Refresh();
-
foreach (ProcessThread thread in process.Threads)
-
{
-
if (thread.ThreadState != System.Diagnostics.ThreadState.Terminated)
-
processFinished = false;
-
}
-
}
-
catch
-
{
-
processFinished = true;
-
}
-
-
return processFinished;
-
}
Just put that in a while loop, so something like: -
while (!CheckProcess(process)) { }
-
If it refreshes the process when its disposed of, it will throw an error, so thats why we have the catch bit just return true. Otherwise, we look to find it when its terminated (fat chance catching right on THAT moment, hence the try/catch).
You are much more likely to run process.Refresh () and have it throw an exception than get the ThreadState to == Terminated when you check. Hence, if you want to be REALLY lazy, you could just see if you could refresh the process and see if that was possible. You might want to throw in the Wait and Unknown depending if the program just sits there after its done (and play around with the output to find out when its finished). In the above example, i was running a number of scripts that exited when done, so I knew that if I couldnt talk to it, they were done.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: S. van Beek |
last post by:
Dear reader,
In case an application is ussing an external model library you have to
address this external model library in your application.
This addressing takes place in a module of the application by opening of a
module and activates and than brows to the location
of the external library.
|
by: Peter |
last post by:
I am using CreateProcessWithLogonW to run an external application, the
problem I am having is that the C# program does not wait until the external
program finishes running before continuing. The external program is a
console application and it does not interact with users, how can I make my
C# program wait until the program initiated by CreateProcessWithLogonW API
completes running before continuing?
here's my API code.
bool ret =...
|
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: snicks |
last post by:
I'm trying to exec a program external to my ASP.NET app using the following
code. The external app is a VB.NET application.
Dim sPPTOut As String
sPPTOut = MDEPDirStr + sID + ".ppt"
Dim p As New System.Diagnostics.Process
'p.Start(MDEPDirStr & "macrun.exe", sPPTOut)
p.Start("C:\WINDOWS\SYSTEM32\CALC.EXE")
'p.Start("C:\WINDOWS\SYSTEM32\macrun.exe", sPPTOut)
|
by: Divyesh |
last post by:
Hello,
I need to call external application from my C# application. I can use
Process.Start(<FileName>) for that but I also need to wait for that
application to finish before I process.
Any clue?
Rgds,
Divyesh
| |
by: NvrBst |
last post by:
I want to send a bunch of keys to an external window using PostMessage.
I send a "KEYDOWN" message (then have to wait for the program to
produce the CHAR message) then send the "KEYUP" message.
Sometimes I have to only wait 1ms, others I have to wait up to 10ms.
Always waiting 10ms for the long messages makes the typing looks
slower... Is there a way to find out when the "CHAR" message was
processed in the external window?
IE, If I...
|
by: Nayan |
last post by:
Hi,
If I make a call to function which is in external library, and it goes
into wait sate.. disabling my app to proceed further, how can I break
this state elegantly? So far, I had to kill my process.
Someone suggested to code multi-threaded app in which one can monitor
other and if one goes into locked state, other kills it.
It sounds okay, but I don't know how to do it. Any code sample or
|
by: Gunnar G |
last post by:
If I wish to run an external application with exec(), does the execution of
the PHP script halt until the external application has finished?
|
by: JasonT |
last post by:
Hi.
I have created a dll in VC++ 08 that exports a CLR windows form class. I call into this dll from an external (closed source, third-party) application to instantiate the form and embed it into the external application window using SetParent(). The problem is, the form runs in the external application window, but the external application no longer updates (renders, responds to close button click, etc.).
Now I know the reason is that in...
|
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: 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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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: 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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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.
| |