I am making a windows application in c# in which on button click i have written some code as
public void btnStart_Click(object sender, EventArgs e)
{
while(true)
{
//some processing
}
}
when i starts application it running continuously.
But on other button i want to stop that application. But i am not getting how to do it?Please help me.
If you want to create a responsive UI, you should never write code like
while (true) {...}because thus you get the main thread busy. Here you really should use BackgroundWorker. Don’t forget to set its WorkerSupportsCancellation property before you start worker thread via RunWorkerAsync(). There is a nice how-to.