/// <summary> /// 创建时刻点环形链表 /// </summary> /// <returns>时刻点环形链表</returns> private LoopLinked <AlarmTime> CreateAlarmLoopLinked() { LoopLinked <AlarmTime> alarmLoopLinked = new LoopLinked <AlarmTime>(); foreach (var item in this._sdTimes.Values) { alarmLoopLinked.AddLast(item); } return(alarmLoopLinked); }
/// <summary> /// 定时操作 /// </summary> /// <param name="para">线程参数</param> private void TimingThreadMethod(ThreadExPara para) { LoopLinked <AlarmTime> alarmLoopLinked = this.CreateAlarmLoopLinked(); if (alarmLoopLinked.Count == 0) { throw new Exception("没有添加时间点"); } // 当前执行次数 int excuteCount = 0; LoopLinkedNode <AlarmTime> currentNode = alarmLoopLinked.FirstNode; TimeSpan tsWait; while (true) { tsWait = this.CaculateWaitTime(currentNode.Value.Time); //如果停止门铃执行 if (para.Token.IsCancellationRequested) { break; } Thread.Sleep(tsWait); //如果停止门铃执行 if (para.Token.IsCancellationRequested) { break; } //响铃 this.OnRing(currentNode.Value.Time); //执行次数验证,如果不为无限次,那么当执行的次数超过要执行的总次数时,就停止 if (this._count != -1) { excuteCount++; if (excuteCount >= this._count) { break; } } currentNode = currentNode.Next; } }