|
-
May 13th, 2013, 04:37 PM
#1
Thread Starter
Hyperactive Member
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
-
May 13th, 2013, 06:31 PM
#2
Re: Display a messagebox aftter all process end
Have you checked to make sure ProcessExit is firing ?
-
May 13th, 2013, 07:40 PM
#3
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!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 13th, 2013, 07:48 PM
#4
Re: Display a messagebox aftter all process end
 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.
-
May 13th, 2013, 07:49 PM
#5
Re: Display a messagebox aftter all process end
 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.
-
May 13th, 2013, 07:51 PM
#6
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.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 13th, 2013, 07:57 PM
#7
Re: Display a messagebox aftter all process end
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!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 14th, 2013, 08:03 AM
#8
Junior Member
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.
-
May 14th, 2013, 10:44 AM
#9
Thread Starter
Hyperactive Member
Re: Display a messagebox aftter all process end
ProcessExit isn't firing... So shall i remove the WaitForExit and the Sleep?
-
May 14th, 2013, 10:47 AM
#10
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.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|