none
Events on application close/open? RRS feed

  • Question

  • 1) In my application i want to know if another application that is already running is closed/exit or not.

    2) Currently by parsing the output of tasklist command prompt (cmd) command, i am able to know whether the application is running or closed.

    3) But the problem is, i have to loop step 2 untill application is closed by the user. Which i dont want to do.

    4) So, Is there any .net class event that shows up when any application of my interest is closed by user gracefully or killed by user through taskmanager ungracefully.

    5) Also, additionally is there any .net class event that shows up when any application of my interest is opened or starts running.

    Thursday, February 21, 2013 9:25 AM

Answers

All replies

  • You could essentially poll for the information on a regular bases using something like this:

    Process[] pname = Process.GetProcessesByName("notepad");
    if (pname.Length == 0)
      MessageBox.Show("nothing");
    else
      MessageBox.Show("run");

    I hope this is helpful.

    -Glenn Thimmes

    Thursday, February 21, 2013 9:34 AM
  • Thanks "gthimmes". I got a clues from your replay. Well, i didn't pool. I used the Exited event of the process(Process.GetProcessesByName). So, this event raises when the application is closed.

    Is there any event that raises when any application is opened?

    Thursday, February 21, 2013 10:37 AM
  • It looks like you might be able to do this with the WMI Win32_ProcessTrace classes. There is another thread here that seems to cover it. 

    Good Luck,

    -Glenn Thimmes

    ---------------------------------------------------------------------------

    Please mark this past as answered if it solved your problem.

    Thursday, February 21, 2013 3:26 PM
  • Hi Liverth,

    Welcome to the MSDN Forum.

    Please try the startup event and exit event in VB.net: 

        Partial Friend Class MyApplication
    
            Private Sub MyApplication_Shutdown(sender As Object, e As System.EventArgs) Handles Me.Shutdown
    
            End Sub
    
            Private Sub MyApplication_Startup(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
    
            End Sub
        End Class

    You can access these event from the project property page, it is on the application tab, and it is a button named view application events: http://msdn.microsoft.com/en-us/library/f2bys999(v=vs.100).aspx  

    Here is the answer about C#: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/2d14dc18-d7bf-4860-88e6-0445e5f9e1b5/

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, February 22, 2013 3:05 AM
    Moderator