Hi Seth,
In fact, i have listbox [too many topic i' opened recently
] , and
the selected items of listbox is a parameter of my external process, i
want to create a "batch" processing program which process TILL the end
of listbox index NON-STOP/no user-prompt. Classic batch process of
programs on the earth
Dim psInfo As New System.Diagnostics.ProcessStartInfo("external.exe",
listbox1.selecteditem)
psInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Normal
psInfo.WorkingDirectory = Application.StartupPath
psInfo.WindowStyle = ProcessWindowStyle.Normal
Dim myProcess As Process =
System.Diagnostics.Process.Start(psInfo)
myProcess.WaitForExit()
If myProcess.HasExited = True Then
Try
Me.ListBox1.SelectedIndex =
Me.ListBox1.SelectedIndex + 1
System.Diagnostics.Process.Start("lame.exe", "
Catch
MsgBox("All files have been converted",
MsgBoxStyle.Information, "Done!")
End Try
But as you see after "try" , the program process the next item then it
stops as normal, but i want to do a batch process TILL the end of
listbox's ALL items. (all the listbox items, one by one).
I hope you understood.
Very thanks...
How about this?
Just add this to the code-behind for Form1 in a new Windows
Application and run the application.
/////////////
Imports System.Diagnostics
Public Class Form1
Private listBox As ListBox
Private button As Button
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'// Create our listbox
listBox = New ListBox()
Me.Controls.Add(listBox)
listBox.Location = New Point(3, 3)
'// Add some values to the listbox
listBox.Items.Add("
www.microsoft.com")
listBox.Items.Add("
www.google.com")
listBox.Items.Add("
www.yahoo.com")
listBox.Items.Add("
www.newegg.com")
'// Create a button to start the batch
button = New Button()
button.Text = "Start Processes"
Me.Controls.Add(button)
button.Location = New Point(12, 105)
button.Size = New Size(100, 23)
AddHandler button.Click, AddressOf button_Click
End Sub
Private Sub button_Click(ByVal sender As Object, ByVal e As
EventArgs)
Dim index As Integer = listBox.SelectedIndex
'// Don't process anything if the user didn't select an item
If index < 0 Then Return
Try
'// Prevent a new item from being selected
'// or the user starting the process again
listBox.Enabled = False
button.Enabled = False
While listBox.Items.Count > index
Try
Dim startInfo As New ProcessStartInfo("ping.exe",
listBox.Items(index).ToString())
startInfo.WindowStyle = ProcessWindowStyle.Normal
startInfo.WorkingDirectory =
Application.StartupPath
Dim p As Process = Process.Start(startInfo)
While Not p.HasExited
'// Do some lazy, fake multithreading
Application.DoEvents()
End While
'Process.Start("lame.exe")
Finally
listBox.Items.Remove(listBox.Items(index))
End Try
End While
MessageBox.Show("All files have been converted", "Done!",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Finally
'// Re-enable the ListBox and Button
listBox.Enabled = True
button.Enabled = True
End Try
End Sub
End Class
/////////////
It starts processing items at the SelectedIndex and removes them after
it's finished.
By the way, in your code you are misusing the "Catch" statement. Catch
is used to handle an exception, so in essence what you are doing is
telling the user that everything is finished whenever you have an
error.
Thanks,
Seth Rowe