Form freezes during while loop

Viewed 18552

I have a piece of code that checks if a certain application is running

while (Process.GetProcessesByName("notepad").Length == 0)
{
     System.Threading.Thread.Sleep(1000);
}

It will check if the user is running notepad but it makes the form freeze and stop responding after a few seconds. I don't know if there is a better solution to fix this problem.

3 Answers
Related