CancellationTokenSource cts1 = new CancellationTokenSource();
CancellationTokenSource cts2 = new CancellationTokenSource();
CancellationTokenSource cts3 = new CancellationTokenSource();
public async Task Numbers(TextBox textbox, CancellationToken token)
{
Random rnd = new Random();
while (token.IsCancellationRequested==false)
{
textbox.Text = rnd.Next(1, 10).ToString();
await Task.Delay(100);
}
}
public async void Check(TextBox textbox, Button button, CancellationTokenSource cts)
{
if (button.Text=="Пуск")
{
var task = Task.Run(()=>Numbers(textbox, cts.Token),cts.Token);
button.Text = "Стоп";
}
else if (button.Text=="Стоп")
{
cts.Cancel();
button.Text = "Пуск";
}
if (button1.Text=="Пуск" && button2.Text == "Пуск" && button3.Text == "Пуск")
{
textBox1.Text = Determine(textBox2, textBox3, textBox4);
}
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Check(textBox2, button1, cts1);
}
private void button2_Click(object sender, EventArgs e)
{
Check(textBox3, button2, cts2);
}
private void button3_Click(object sender, EventArgs e)
{
Check(textBox4, button3, cts3);
}