Results 1 to 3 of 3

Thread: Creating an event handler to find out when a process starts

  1. #1

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Creating an event handler to find out when a process starts

    Hi everyone. Me again. I have a little problem I hope somebody help me. I know how to create an event handler to a process such as notepad so that when the process is exited, some kind of event is triggered eg.

    private Process NPad;
    ...


    Process[] p = Process.GetProcessesByName("notepad");

    if(p.Length > 0)
    {
    NPad = p[0];
    lbl1.Text = "Notepad is started.";
    NPad.EnableRaisingEvents = true; // Set Enable events to true.
    NPad.Exited += new EventHandler(NPad_Exited); // Set the event handler.
    }


    ....

    // Event handler code
    private void NPad_Exited(object sender, EventArgs e)
    {
    // Some Action to be taken e.g.
    lbl1.Text = "Notepad Stopped";

    }

    .
    .
    .
    .
    .
    .
    The problem I am having is that I also want to set some kind of event to trigger when a process like notepad is started and not just exited. The above code shows how to set an event when notepad is exited. Does anyone know how to set an event to trigger when notepad is started?

    Thanking for any kind of help in advance.

    Jennifer.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Creating an event handler to find out when a process starts

    Maybe you can find something here. The third post on the page looks like it would do the trick

  3. #3

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Creating an event handler to find out when a process starts

    Thanks penagate. I will read it over and see if i get the solution, if I do I will put it up here. And wishing you a wonderful 2006 penegate!!! - jennifer

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