-
December 21st, 2007, 09:15 AM
#1
How to know when externally called program ends ?
Hi all...
I am calling one console application from my application and passing some parameters for its execution; after the console program runs successfully, it outputs a text file. and then closes itself automatically. (Takes some time to output text file.)
I want to know when does this program ends. so that i can read the completly created text file.
Is there any way to know this ?
Thanks
MMH.
Regards,
MMH
Rate my post if you find it usefull.
-
December 21st, 2007, 09:20 AM
#2
Re: How to know when externally called program ends ?
It would be easier to make some suggestions if you post some of your code (specifically, the part that opens the console app and the method within this that writes to the textfile)
but hey, maybe someone here has enough guru power to help you without it
It's not a bug, it's a feature!
-
December 21st, 2007, 09:40 AM
#3
Re: How to know when externally called program ends ?
Basically, this is done using 'process.start();'. I am just calling the console executable file with passing some parameters like name + path of the file to output, some commands, etc. Rest of the job is done by the console exe. it will take in the parameters and start working on them. and will output the file. This takes some time. and after creation of the output file, it closes itself.
Now the question is. When do i read the output file ? when will it finish writing it so that i read it completely without missing any information.
I hope this explains in some depth.
thanks
MMH
Regards,
MMH
Rate my post if you find it usefull.
-
December 21st, 2007, 11:28 AM
#4
Re: How to know when externally called program ends ?
Declare and initialize backgroundWorker control
Code:
System.ComponentModel.BackgroundWorker BackgroundWorker1;
private void Form1_Load(object sender, System.EventArgs e)
{
BackgroundWorker1 = new System.ComponentModel.BackgroundWorker();
BackgroundWorker1.DoWork += BackgroundWorker1_DoWork;
BackgroundWorker1.RunWorkerCompleted += BackgroundWorker1_RunWorkerCompleted;
}
Start the BackGroundWorker and disable the btnFileRead
Code:
private void Button1_Click(object sender, System.EventArgs e)
{
BackgroundWorker1.RunWorkerAsync();
TxtStatus.Text = "File Write in Progress...";
btnFileRead.Enabled = false;
}
BackGroundWorker starts the process.
Waits for it to complete.
Enable btnFileRead upon completion.
Code:
private void BackgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
Process p = Process.Start(sAppPath);
p.WaitForExit();
}
private void BackgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
TxtStatus.Text = "File Write Completed";
btnFileRead.Enabled = true;
}
Last edited by aniskhan; December 21st, 2007 at 11:49 AM.
-
December 21st, 2007, 09:52 PM
#5
Re: How to know when externally called program ends ?
or you could use also the "Exit" event of the process object.
Busy
-
December 22nd, 2007, 12:12 AM
#6
Re: How to know when externally called program ends ?
Originally Posted by Thread1
or you could use also the "Exit" event of the process object.
x2
you beat me to it...
the wait for exit is also an excellent method.
I've wrapped quite a few command line applications as a windows app this way.
good luck.
-
December 22nd, 2007, 12:19 AM
#7
Re: How to know when externally called program ends ?
Try to open the textfile with a writelock. You can't until it's written fully.
-
December 25th, 2007, 09:33 PM
#8
Re: How to know when externally called program ends ?
Originally Posted by MadHatter
x2
you beat me to it...
hehe happy holidays!
Busy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|