Firstly, if no notebooks work, you won’t do anything. Perhaps he should write 0 in a textBox?
I suggest rewriting the code as follows:
var processes = Process.GetProcesses().Select(p => p.ProcessName).ToList();
int count = processes.Count(name => String.Compare(name, "notepad", StringComparison.OrdinalIgnoreCase) == 0);
textBox1.Text = Convert.ToString(count);
You will have the opportunity to easily debug and see which items are in the process list.
In addition, your process may be Notepad, not Notepad. So I replaced your equality check with a String.Compare call.
source
share