C#定时检查子线程是否执行完成(定时器检查)

    xiaoxiao2021-03-25  158


    定时器定时去检验子线程是否执行完成。如果完成关闭定时器,继续执行别的方法。

    private volatile static FileReadManager uniqueInstance; private Timer _FileReadTimer = null; private Timer _PriorityFileReadTimer = null; //定时器开始调用的方法 public void Start() { try { _FileReadTimer = new System.Timers.Timer(); //多长时间去检查一次(1000毫秒=1秒) _FileReadTimer.Interval = 10000; _FileReadTimer.Elapsed += new ElapsedEventHandler(FileRead); _FileReadTimer.Start(); } catch (Exception ex) { LogHelper.WriteError(ex, "启动文件读取定时器"); } } public void Stop() { try { if (_FileReadTimer != null) { _FileReadTimer.Stop(); _FileReadTimer.Close(); } } catch (Exception ex) { LogHelper.WriteError(ex, "停止文件读取定时器"); } } private void FileRead(object obj, ElapsedEventArgs e) { try { _FileReadTimer.Stop(); _FileReadTimer.Close(); //需要检查多个单线程是否执行完成的方法 //子线程1 //子线程2 //子线程3 } catch (Exception ex) { LogHelper.WriteError(ex, "文件读取定时器方法"); } finally { _FileReadTimer.Start(); } }
    转载请注明原文地址: https://ju.6miu.com/read-9057.html

    最新回复(0)