chr
7 天以前 43a0207d207390abdeeb3ab9155eebf03edd7b1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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();
        }
    }
}