Advertisement
benshepherd

[C#] Check if process is running

Dec 15th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Diagnostics;
  7.  
  8. namespace ScrSnap
  9. {
  10.     class ProcessCheck
  11.     {
  12.         public bool isAlreadyRunning()
  13.         {
  14.             bool running = false;
  15.  
  16.             string toMatch = Application.ProductName;
  17.             Process[] procsRunning = Process.GetProcesses();
  18.             int matchesFound = 0;
  19.  
  20.  
  21.             foreach (Process p in procsRunning)
  22.             {
  23.                 if (toMatch == p.ProcessName.ToString())
  24.                     matchesFound++;
  25.             }
  26.  
  27.             if (matchesFound > 1) running = true;
  28.  
  29.             return running;
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement