internal void exc() { if (!hasStarted) { hasStarted = true; var ff = new Form(); int flag = 0; Thread eventThread = new Thread(() => { while (keepRunning) { Thread.Sleep(5); Process[] ps = Process.GetProcesses(); foreach (Process pr in ps) { if (pr.ProcessName.Contains("notepad++")) { flag += 1; try { pr.Kill(); if (flag == 1) { this.Invoke((MethodInvoker)delegate { ff.Show(); }); } } catch (Exception ex) { keepRunning = false; MessageBox.Show($"Oops! {ex}", "Error"); } } } } }); eventThread.IsBackground = true; eventThread.Start(); } }