Guest greifedc Posted October 31, 2002 Posted October 31, 2002 I am looping system.diagnostics.process.start this code works when I put a break in the code and single step it thru waiting for each line to finish. but if I don't use a break or step it thru quickly the process I am trying to start doesn't have a chance to finish the first time around before it loops and is ready to start again. Is there a way to make it wait for a process before moving on to the next? Dim ProgramsSelected As Int16 Dim count As Int16 = 0 ProgramsSelected = newProgramList.SelectedItems.Count Do count += 1 System.Diagnostics.Process.Start _(newProgramList.SelectedItem) newProgramList.SetSelected _(newProgramList.SelectedIndex, False) Loop Until count = ProgramsSelected :confused: Quote
Administrators PlausiblyDamp Posted November 13, 2002 Administrators Posted November 13, 2002 try altering to the following code. Notice the p.WaitForExit method after p.Start Dim ProgramsSelected As Int16 Dim count As Int16 = 0 ProgramsSelected = newProgramList.SelectedItems.Count Do count += 1 Dim p As New System.Diagnostics.Process() p.Start(newProgramList.SelectedItem) p.WaitForExit() newProgramList.SetSelected _(newProgramList.SelectedIndex, False) Loop Until count = ProgramsSelected Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
*Gurus* divil Posted November 14, 2002 *Gurus* Posted November 14, 2002 A nicer way would be to use the event-driven method: Dim WithEvents myProcess As Process Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click myProcess = Process.Start("c:\windows\notepad.exe") myProcess.EnableRaisingEvents = True End Sub Private Sub myProcess_Exited(ByVal sender As Object, ByVal e As System.EventArgs) Handles myProcess.Exited MessageBox.Show("Exited!") End Sub Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Rick_Fla Posted March 17, 2004 Posted March 17, 2004 A nicer way would be to use the event-driven method: Dim WithEvents myProcess As Process Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click myProcess = Process.Start("c:\windows\notepad.exe") myProcess.EnableRaisingEvents = True End Sub Private Sub myProcess_Exited(ByVal sender As Object, ByVal e As System.EventArgs) Handles myProcess.Exited MessageBox.Show("Exited!") End Sub If I understand this correctly, the process will not fire again until it is completed? Even if it is in a loop? I have an application that downloads an unknow number of files, has to decrypt each one, then process them. So as long as I use this, it should wait for the process to complete on each file? Quote "Nobody knows what I do until I stop doing it."
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.