trigger an event when an application stops

Posted on 2007-08-09
Last Modified: 2013-11-05
I have a program i wrote, lets call it ProgramA...  basically it opens another program lets call it ProgramZ, and gains a handle to the program using the User32.dll.  What im trying to do is have ProgramA display a message box when ProgramZ gets closed (when the user closes ProgramX).
Question by:rodmjay
    LVL 23

    Expert Comment

    by:Jens Fiederer
    You can have ProgramA dedicate a thread to using System.Diagnostics.Process.WaitForExit, and have the thread exit and raise the event in the UI thread.
    LVL 8

    Author Comment

    sounds cool... how does that look in code?
    LVL 23

    Accepted Solution

    Say you have this function "Vulture" (translating here from my C#) designed to wait for the dead.

    (you'll need to import system.threading and system.diagnostics for this)

    private pid as int

    Sub Vulture()
        dim proc as Process = Process.GetProcessById(pid)
        MessageBox.Show("it died")
    End Sub

    You invoke this Sub from your code with:
                    dim t as Thread  = new Thread(new ThreadStart(Vulture))
    and then go on with your code.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now