0
  • I am creating an application in C# for monitoring some applications, so how to know when an exe running (ex: notepad).

  • I tried using timer run check if (Process.GetProcessesByName("process_name").Length > 0) every 1s but maybe not the good way.

JimmyN
  • 579
  • 4
  • 16

2 Answers2

0

I think best approach would be to set timer which will check for running processes every, let's say, 5 seconds. In timer Tick event, check for running process by it's name

// This will return an empty array if notepad isn't running.
Process[] localByName = Process.GetProcessesByName("notepad");

take a look at MSDN documentation

Nino
  • 6,931
  • 2
  • 27
  • 42
0

i'm building an application same for u. It's is my solution:

public void findProcess(string processName)
    {
        BackgroundWorker bg = new BackgroundWorker();
        bg.DoWork += (object sender, DoWorkEventArgs e){
            while(true)
            {
                Process[] process = Process.GetProcesses();
                foreach(var p in process )
                    if(p.ProcessName.Equals(processName))
                    {
                        // TODO:
                    }

                Thread.Sleep(1000);
            }            
        };
    }