using System;
|
using System.Diagnostics;
|
using System.Threading;
|
using System.Threading.Tasks;
|
|
namespace Test1
|
{
|
public class Intercepter
|
{
|
private Task importListenTask;
|
private Task checkInListenTask;
|
|
private CancellationTokenSource cts;
|
|
public Intercepter(Action callback1, Action callback2)
|
{
|
cts = new CancellationTokenSource();
|
/// 启动导入拦截
|
importListenTask = Task.Run(() =>
|
{
|
while (!cts.IsCancellationRequested)
|
{
|
Debug.WriteLine("inter Import");
|
// 监听导入插件的启动
|
callback1();
|
Thread.Sleep(30);
|
}
|
});
|
/// 启动检入拦截
|
checkInListenTask = Task.Run(() =>
|
{
|
while (!cts.IsCancellationRequested)
|
{
|
Debug.WriteLine("inter CheckIn");
|
// 监听检入插件的启动
|
callback2();
|
Thread.Sleep(30);
|
}
|
});
|
}
|
|
public void StopIntercept()
|
{
|
cts.Cancel();
|
}
|
}
|
}
|