线程循环监听方法
记录一下
private readonly List<Thread> threads = new List<Thread>();
/// <summary>
/// 线程循环监听
/// </summary>
private void ClearPutLogMes()
{
//if (times <= 0)
//{
// times++;
// return;
//}
foreach (var thread in threads)
{
thread.Abort();
}
threads.Clear();
var t = new Thread(() =>
{
while (true)
{
Thread.Sleep(6000);
Invoke(new Action(() =>
{
//需要监听的逻辑
}));
Thread.Sleep(300000);
}
})
{
IsBackground = true,
Name = "Name" + Guid.NewGuid().ToString("N")
};
t.Start();
threads.Add(t);
}