|
-
May 1st, 2007, 04:24 PM
#1
Thread Starter
Lively Member
[RESOLVED] [2005] ProcessStartInfo Question
Hi All,
English is not native.
I using the following code to extract files in console windows which is hidden.
I want to make this process "wait" and not continue with the next line of my application until this process has been finished and then execute the next line of code.
how can I do that?
vb Code:
Try
'Using the 'EXTRACT.EXE' to open cab files
Dim MyProcess As New ProcessStartInfo("extract.exe", "/e bla.cab)
MyProcess.CreateNoWindow = True
MyProcess.WindowStyle = ProcessWindowStyle.Hidden
Process.Start(MyProcess)
Catch ex As Exception
MessageBox.Show("Extracting Files Error", "BLA", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Last edited by vbdc; May 1st, 2007 at 07:47 PM.
-
May 1st, 2007, 04:34 PM
#2
Re: [2005] ProcessStartInfo Question
the process has a WaitForExit method, but it blocks the thread so what you should do is use AddHandler to add an event handler for the Exited event:
VB Code:
Try
Dim MyProcess As New ProcessStartInfo("extract.exe", "/e bla.cab")
MyProcess.CreateNoWindow = True
MyProcess.WindowStyle = ProcessWindowStyle.Hidden
Process.Start(MyProcess)
AddHandler MyProcess.Exited, AddressOf ProcessExited
Catch ex As Exception
MessageBox.Show("Extracting Files Error", "BLA", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Private Sub ProcessExited(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Do what you need to do after the process has exited in here
End Sub
-
May 1st, 2007, 04:37 PM
#3
Thread Starter
Lively Member
Re: [RESOLVED] [2005] ProcessStartInfo Question
-
May 1st, 2007, 07:40 PM
#4
Thread Starter
Lively Member
Re: [RESOLVED] [2005] ProcessStartInfo Question
hi Atheist
Ok, the ProcessExited does not start automaticly and I should call it.
What type of agruments should I pass to 'ProcessExited' sub?
Thanks
Last edited by vbdc; May 1st, 2007 at 08:20 PM.
-
May 1st, 2007, 08:40 PM
#5
Thread Starter
Lively Member
Re: [2005] ProcessStartInfo Question
Solved.
I had to add the following line:
MyProcess.SynchronizingObject = Me
Thanks
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
|