Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to Start a 2nd Process When the 1st has exited 1

Status
Not open for further replies.

larrydavid

Programmer
Jul 22, 2010
174
US
Hello, I have a windows service that runs in a System.Thread which starts a timed event each day at a certain time, which works fine. Within this event I have processes I am trying to make dependent. Here is a snippet fron the OnTimedEvent method:

Private Sub OnTimedEvent(ByVal state As Object)

' Stop the existing timer...
oTimer.Dispose()

Try
testProcess1 = Process.Start("C:\Test\1\mspaint.exe")
If testProcess1.HasExited Then
testProcess1.Close()
testProcess2 = Process.Start("C:\Test\2\notepad.exe")
End If
Catch e As Exception
'Console.WriteLine("The following exception was raised: ")
'Console.WriteLine(e.Message)
myLog.WriteEntry((e.Message), EventLogEntryType.Information)
End Try

End Sub

The first process (MSPaint.exe) launches fine when the service starts, but when I go into TaskManager and End Process, the next process (notepad.exe) doesn't start.

If someone could please show me what I am overlooking I would greatly appreciate it.

Thanks,
Larry
 
This line:

If testProcess1.HasExited Then

executes well before you have a chance to close the MSPaint process. You need to add this line before the If statement:

testProcess1.WaitForExit()

This will pause code execution until testProcess1 exits, then continue.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thank you jebenson! I don't know you but I just fell in love with ya! Many thanks! --Larry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top