topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday April 19, 2024, 6:16 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Waiting for program completion in Visual Basic 2008  (Read 5847 times)

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,626
    • View Profile
    • Donate to Member
Waiting for program completion in Visual Basic 2008
« on: February 11, 2008, 12:20 AM »
I am trying to run multiple (anywhere from 2 to 6) programs after the user clicks a button. I can do that just fine, with the exception of them all starting at once. I have tried using the Shell command and using that to Wait, however VB9 doesn't allow that to do anything, so I am stuck with Process.Start("myprocess.exe").

I need to know how to wait for the first program to complete its work and close before executing the next (I don't want to get into loops or anything timer based, if that is possible). I don't want it to time out and run the next program- it has to wait for the program to close to work properly.

Anyone?

-Brandon

mwb1100

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,645
    • View Profile
    • Donate to Member
Re: Waiting for program completion in Visual Basic 2008
« Reply #1 on: February 11, 2008, 01:15 AM »
If I understand your question right, then all you have to do is call the WaitForExit() method on the Process object returned by Process.Start( "myprocess.exe").  Something like:

Code: vb.net [Select]
  1. Dim proc as Process
  2.  
  3. proc = Process.Start( "myprocess.exe")
  4. proc.WaitForExit()
  5.  
  6. proc = Process.Start( "myprocess2.exe")
  7. proc.WaitForExit()
  8.  
  9. ' and so on...

« Last Edit: February 11, 2008, 01:57 AM by mwb1100 »

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,626
    • View Profile
    • Donate to Member
Re: Waiting for program completion in Visual Basic 2008
« Reply #2 on: February 11, 2008, 04:52 PM »
Yes, exactly what I was looking for! Thanks!!! :)

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,288
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: Waiting for program completion in Visual Basic 2008
« Reply #3 on: February 20, 2008, 03:21 PM »
Just a note, but I think that you should make sure that you spin that code off into another thread and poll it for completion.

Otherwise you may end up with some nastiness.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

mahesh2k

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,426
    • View Profile
    • Donate to Member
Re: Waiting for program completion in Visual Basic 2008
« Reply #4 on: February 21, 2008, 07:24 AM »
 ;D
i accidently thought it means logic completion that could ruin alll human programmers and will start the AI rage like this one.
http://www.swatkats.us/unlikely_alloys

:)

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: Waiting for program completion in Visual Basic 2008
« Reply #5 on: February 21, 2008, 09:23 AM »
Just a note, but I think that you should make sure that you spin that code off into another thread and poll it for completion.

Otherwise you may end up with some nastiness.
DON'T POLL!

If he's doing a GUI and doesn't want to lock that up, sure, put program launch in a work thread. But don't frigging poll, have the worker-thread post a "I'm done" message to the GUI thread. Polling is evil and lame, except for a very small set of problems.

- carpe noctem