I have a question about using threads. I have an application in WinForms. I have a start button with a method. When I click on it the method starts performing and lasts for a long time. When the method is performing the Form is not active I can't even close it until the method ends. I want to make the Form active and click on another button (Stop button) to stop method performing.
private void start_Click(object sender, EventArgs e)
{
StartLoading() //Some Method which performing I want to stop at any time
}
private void stop_Click(object sender, EventArgs e)
{
//Stop performing Method from start_Click
}
I tryed to use the next code:
private void start_Click(object sender, EventArgs e)
{
Thread StartThread = new Thread(StartLoading);
StartThread.Start();
}
public void StartLoading()
{
}
And it works. The method is performing while the Form remains active. But I don't know how to stop this thread on stop_Click event. Maye there is another way to do what I want??
Best Regards Sergey