[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
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
Re: [RESOLVED] [2005] ProcessStartInfo Question
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
Re: [2005] ProcessStartInfo Question
Solved.
I had to add the following line:
MyProcess.SynchronizingObject = Me
Thanks