C# 线程
private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
//开始线程 Task.Factory.StartNew(() => { while (!cancellationTokenSource.IsCancellationRequested) { try { catch (Exception ex) { throw new Exception(ex.Message); } finally { } } }, cancellationTokenSource.Token);
//设置退出循环 cancellationTokenSource.Cancel();