Hi guys I start threads with such code:
Thread[] thr;
private void button1_Click(object sender, EventArgs e)
{
decimal value = numericUpDown2
You can use a CancellationToken
to signal when the operation should stop.
Create a CancellationTokenSource
as an instance field of your type that you initialize in the button click handler.
In your background method periodically check the IsCancellationRequested
property of the Token
in the token source, or call ThrowIfCancellationRequested()
if you want it to just throw an exception if it is canceled.
When you want to stop the threads call Cancel
on the token source.