using ConLink.Enthernet; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace DTTest { public partial class ActControl { /// /// 是处于活跃状态 /// 2021.3.31 /// public bool isActive { get; set; } = false; /// /// 播放的指针 /// private int indexPlay { get; set; } = 0; /// /// 播放的状态 /// private bool isPlay { get; set; } = false; /// /// /// private List sendList { get; set; } = null; /// /// 2020-8-6 /// public event Action CurrRunInfoEvent; /// /// 2021.1.4 /// 上午11.15 /// public event Action PlayTaskEnd; /// /// /// public Thread t_Play = null; /// /// 构造函数 /// /// /// public ActControl() { } /// /// 播放序列 /// /// public ActControl PlayData(List sendList) { this.sendList = sendList; t_Play = new Thread(new ParameterizedThreadStart(PlayData)); t_Play.IsBackground = true; t_Play.Name = "123"; t_Play.Start(sendList); return this; } private void PlayData(object obj) { var frams = (List)obj; while (indexPlay <= sendList.Count - 1) { if (isPlay) { var frame = frams[indexPlay]; indexPlay++; CurrRunInfoEvent?.Invoke(indexPlay, sendList.Count, frame); } Thread.Sleep(PP.PCP.SendInterval); } isPlay = false; isActive = false; indexPlay = 0; PlayTaskEnd?.Invoke(); } /// /// 返回播放状态 /// /// public bool PlayState() { return isPlay; } /// /// 返回活跃状态 /// /// public bool ActiveState() { return isActive; } /// /// 播放 /// public ActControl Play() { isActive = true; isPlay = true; return this; } /// /// 暂停 /// public ActControl Suspend() { isPlay = false; return this; } /// /// 终了 /// public ActControl End() { if (t_Play != null) { t_Play.Abort(); } isPlay = false; isActive = false; indexPlay = 0; PlayTaskEnd?.Invoke(); return this; } /// /// /// /// public ActControl SetIndex(int index) { indexPlay = index; return this; } } }