I have developed a socket program . I have the problem with the client side socket program it gets data from multiple servers,one at a time and update the details in listview. It happens inside a infinite loop.
while(true)
{
}
I want to exit this this loop in the middle period, I used button click event to do that
foreach (Process myProc in Process.GetProcesses())
{
if (myProc.ProcessName == "procees name")
{
myProc.Kill();
}
}
but it’s too slow, I want to pause that process and kill it. Help me to pause currently running process.
Since you mention the process is your own application, you can just exit the application yourself instead of killing the application. Your question turns out more to be “how can I exit my program”.
Firstly, your button may not seem responsive since you’re running an infinite loop. One (bad) way of doing it is like this:
Application.DoEventsis important to make your application keep listening to other actions. And then,The ideal way imo is to transfer the job of getting data from servers to a background process. May be something like this:
And then upon your cancellation click,