Results 1 to 10 of 10

Thread: Display a messagebox aftter all process end

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    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

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Display a messagebox aftter all process end

    Have you checked to make sure ProcessExit is firing ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Display a messagebox aftter all process end

    Quote Originally Posted by dunfiddlin View Post
    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Display a messagebox aftter all process end

    Quote Originally Posted by dunfiddlin View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  8. #8
    Junior Member
    Join Date
    Apr 2013
    Posts
    17

    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.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    336

    Re: Display a messagebox aftter all process end

    ProcessExit isn't firing... So shall i remove the WaitForExit and the Sleep?

  10. #10
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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
  •  



Click Here to Expand Forum to Full Width