Results 1 to 5 of 5

Thread: [RESOLVED] [2005] ProcessStartInfo Question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    89

    Resolved [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:
    1. Try
    2.             'Using the 'EXTRACT.EXE' to open cab files
    3.             Dim MyProcess As New ProcessStartInfo("extract.exe", "/e bla.cab)
    4.             MyProcess.CreateNoWindow = True
    5.             MyProcess.WindowStyle = ProcessWindowStyle.Hidden
    6.             Process.Start(MyProcess)
    7.         Catch ex As Exception
    8.             MessageBox.Show("Extracting Files Error", "BLA", _
    9.             MessageBoxButtons.OK, MessageBoxIcon.Error)
    10.         End Try
    Last edited by vbdc; May 1st, 2007 at 07:47 PM.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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:
    1. Try
    2.             Dim MyProcess As New ProcessStartInfo("extract.exe", "/e bla.cab")
    3.             MyProcess.CreateNoWindow = True
    4.             MyProcess.WindowStyle = ProcessWindowStyle.Hidden
    5.             Process.Start(MyProcess)
    6.             AddHandler MyProcess.Exited, AddressOf ProcessExited
    7.         Catch ex As Exception
    8.             MessageBox.Show("Extracting Files Error", "BLA", _
    9.             MessageBoxButtons.OK, MessageBoxIcon.Error)
    10.         End Try
    11.  
    12. Private Sub ProcessExited(ByVal sender As System.Object, ByVal e As System.EventArgs)
    13.             'Do what you need to do after the process has exited in here
    14. End Sub
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    89

    Re: [RESOLVED] [2005] ProcessStartInfo Question

    Thanks Alot

    VBDC

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    89

    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    89

    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
  •  



Click Here to Expand Forum to Full Width