473,804 Members | 3,789 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cant put a wait on external application?

11 New Member
Hello all,

I have problems letting this application wait. I tried everything in my knowledge.
Here is the code:

Expand|Select|Wrap|Line Numbers
  1.                     System.Diagnostics.Process procdemux = new System.Diagnostics.Process();
  2.                     procdemux.StartInfo.UseShellExecute = true;
  3.                     procdemux.StartInfo.CreateNoWindow = false;
  4.                     procdemux.StartInfo.RedirectStandardOutput = false;
  5.                     procdemux.StartInfo.FileName = currentPath + "\\res\\demux.bat";
  6.                     procdemux.Start();
  7.                     procdemux.WaitForExit(3000);
  8.                     procdemux.Close();
  9.  
this code follows it up:

Expand|Select|Wrap|Line Numbers
  1.             System.Diagnostics.Process procencode = new System.Diagnostics.Process();
  2.             procencode.StartInfo.UseShellExecute = true;
  3.             procencode.StartInfo.CreateNoWindow = false;
  4.             procencode.StartInfo.RedirectStandardOutput = false;
  5.             procencode.StartInfo.FileName = currentPath + "\\res\\encode.bat";
  6.             procencode.Start();
  7.             procencode.WaitForExit(3000);
  8.             procencode.Close(); 
  9.  
Can someone please help me?

Thanks in advance!

Regards,

Dennis
Jun 4 '07 #1
12 1444
FLX
11 New Member
please, someone?

Regards,

Dennis
Jun 6 '07 #2
Atran
319 Contributor
Hello, I do not know this way, but I learn another way to stop your app:

Expand|Select|Wrap|Line Numbers
  1. //Stop your app for 1000 milliseconds.
  2. System.Threading.Thread.Sleep(1000);
  3.  
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.
Jun 6 '07 #3
mwalts
38 New Member
Hello, I do not know this way, but I learn another way to stop your app:

Expand|Select|Wrap|Line Numbers
  1. //Stop your app for 1000 milliseconds.
  2. System.Threading.Thread.Sleep(1000);
  3.  
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
Jun 6 '07 #4
Plater
7,872 Recognized Expert Expert
You're currently only waiting 3 seconds before you are manually closing that process. Seems a bit quick?
Jun 6 '07 #5
rancid11
3 New Member
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);


}
Jun 24 '07 #6
blackjack2150
79 New Member
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);
}
Jun 25 '07 #7
rancid11
3 New Member
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.
Jun 25 '07 #8
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
Jun 26 '07 #9
TRScheel
638 Recognized Expert Contributor
Why havent I seen this thread earlier?

Anyways, this will be useful to you:

Expand|Select|Wrap|Line Numbers
  1. private static bool CheckProcess(Process process)
  2. {
  3.     bool processFinished = true;
  4.     try
  5.     {
  6.         process.Refresh();
  7.         foreach (ProcessThread thread in process.Threads)
  8.         {
  9.             if (thread.ThreadState != System.Diagnostics.ThreadState.Terminated)
  10.                 processFinished = false;
  11.         }
  12.     }
  13.     catch
  14.     {
  15.         processFinished = true;
  16.     }
  17.  
  18.     return processFinished;
  19. }
Just put that in a while loop, so something like:

Expand|Select|Wrap|Line Numbers
  1. while (!CheckProcess(process)) { }
  2.  

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.
Jun 26 '07 #10

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

Similar topics

1
2000
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.
4
17084
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 =...
4
2557
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()
5
3650
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)
1
1920
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
0
1715
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...
5
1868
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
1
5626
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?
1
1615
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...
0
9706
marktang
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...
0
10332
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 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...
0
10077
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 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...
0
9150
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, 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...
1
7620
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 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...
0
6853
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();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4299
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
2
3820
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.