Display a messagebox aftter all process end
Hi,
Can someone help, after all process finish, it should show the message box and it's not...
Code:
Public Class InstallPrograms
Dim pCount As Integer
Dim p() As Process
Sub InstallPrograms_KeyUp(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyUp
If e.KeyData = Keys.F1 Then
Editor.ShowDialog()
End If
End Sub
Private Sub InstallPrograms_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
'Me.Text = "Post Install By Chris2k" + SelectPrograms.ver
For Each App As ListViewItem In SelectPrograms.App_List.CheckedItems
Label3.Text = "Installing " + App.SubItems(0).Text
Label3.Refresh()
Label5.Refresh()
Dim File As New System.Diagnostics.ProcessStartInfo
File.FileName = App.SubItems(3).Text
Dim Installer As New System.Diagnostics.Process
Installer.StartInfo = File
Installer.Start() 'Start the process
Installer.WaitForExit() 'Wait until the process started is finished
Installer.Close() 'Release the resources
Label5.Text = "Install Complete..."
Label5.Refresh()
System.Threading.Thread.Sleep(750)
Label5.Text = ""
Label5.Refresh()
Next
' We'll assume you have all the filepaths in a listbox
' it would work the same for any other collection type
pCount = SelectPrograms.App_List.CheckedItems.Count
ReDim p(pCount - 1)
For i = 0 To pCount - 1
p(i) = New Process With {.EnableRaisingEvents = True}
AddHandler p(i).Exited, AddressOf ProcessExit
p(i).StartInfo.FileName = SelectPrograms.App_List.Items(i).SubItems(3).Text
'p(i).Start()
Next
End Sub
Private Sub ProcessExit(ByVal sender As Object, ByVal e As System.EventArgs)
pCount -= 1
If pCount = 0 Then
MsgBox("All Done")
End If
End Sub
End Class
Re: Display a messagebox aftter all process end
Have you checked to make sure ProcessExit is firing ?
Re: Display a messagebox aftter all process end
System.Threading.Thread.Sleep(750)
If processes exit whilst the application is sleeping then ProcessExit cannot fire. You can't retrieve an event from the past!
Re: Display a messagebox aftter all process end
Quote:
Originally Posted by
dunfiddlin
System.Threading.Thread.Sleep(750)
If processes exit whilst the application is sleeping then ProcessExit cannot fire. You can't retrieve an event from the past!
Hmm...that could be the problem but would not be surprised if it was not. The .Net framework marshals calls to delegates on the UI thread by utilizing the message loop. It posts the request to the message queue and when the message loop gets around to reading that message it will call the delegate. I'd imagine that if the process quits while the UI is sleeping, that wouldn't stop the Process class from posting a call to raise that event to the message queue which means it can be raised long after the process has quit.
Re: Display a messagebox aftter all process end
Quote:
Originally Posted by
dunfiddlin
System.Threading.Thread.Sleep(750)
If processes exit whilst the application is sleeping then ProcessExit cannot fire. You can't retrieve an event from the past!
In that case the event will be queued and its handler executed after the sleep period.
As far as I can tell, the issue here is that you are calling WaitForExit on each Process, so the Exited event of your processes is never going to be raised because the process has already exited.
Re: Display a messagebox aftter all process end
Well there's only one way to find out! (Sadly my dogs are crossing their legs and looking imploringly at me so I won't be able to test it myself tonight!) It has always been my impression that Sleep on the UI thread literally knocks the application unconscious but it will be interesting to see.
Re: Display a messagebox aftter all process end
Quote:
calling WaitForExit on each Process, so the Exited event of your processes is never going to be raised
Ah, that makes sense! I am relieved to discover that my original answer on this issue did not include WaitForExit and that any problems the OP has with it are therefore entirely down to him! Now I really gotta go let these dogs water the plants and go to bed! See y'all on the morrow!
Re: Display a messagebox aftter all process end
I think that “ProcessExit” is not getting triggered and thus the past events are not retrieving, as a result the messagebox is not displaying at the end.
Re: Display a messagebox aftter all process end
ProcessExit isn't firing... So shall i remove the WaitForExit and the Sleep?
Re: Display a messagebox aftter all process end
Renove WaitForExit and try it. If that's still not working, remove the sleep. Any problems after that need a new explanation.