You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
883 B

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CancellationTokenTest
{
public class Client
{
private CancellationTokenSource _cts;
private uint _cnt;
public void Start()
{
Console.WriteLine("[Call Start]");
_cts = new CancellationTokenSource();
Task.Run(() =>
{
while (true)
{
Thread.Sleep(30);
if (_cts.IsCancellationRequested)
break;
Console.WriteLine(_cnt++);
//Thread.Sleep(100);
}
}, _cts.Token);
}
public void Cancel()
{
Console.WriteLine("[Call Cancel]");
_cts.Cancel();
}
}
}