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.
45 lines
1.1 KiB
45 lines
1.1 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace FangYar.Common
|
|
{
|
|
/// <summary>
|
|
/// Task线程统一控制帮助类
|
|
/// </summary>
|
|
public class MyTaskControlHelper
|
|
{
|
|
/// <summary>
|
|
/// 控制Task是否退出
|
|
/// </summary>
|
|
private static CancellationTokenSource tokenSource;
|
|
|
|
/// <summary>
|
|
/// 控制Task是否暂停
|
|
/// </summary>
|
|
private static ManualResetEvent resetEvent = new ManualResetEvent(true);
|
|
|
|
/// <summary>
|
|
/// 获取Task退出控制器
|
|
/// </summary>
|
|
public static CancellationTokenSource TokenSource
|
|
{
|
|
get
|
|
{
|
|
if (tokenSource == null)
|
|
{
|
|
tokenSource = new CancellationTokenSource();
|
|
}
|
|
return tokenSource;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获取Task暂停控制器
|
|
/// </summary>
|
|
public static ManualResetEvent ResetEvent { get { return resetEvent; } }
|
|
|
|
}
|
|
}
|
|
|