Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

trigger an event when an application stops

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).
  • 2
1 Solution
Jens FiedererTest Developer/ValidatorCommented:
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.
rodmjayAuthor Commented:
sounds cool... how does that look in code?
Jens FiedererTest Developer/ValidatorCommented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now