/// <summary>模块启动</summary> public void Start(int count) { #if DEBUG XTrace.WriteLine("进入任务模块 当前计数{0}", count); #endif DisplayGlobal.log.Write(string.Format("进入任务更新模块 当前计数{0}", count)); _token = new CancellationTokenSource(); var _module = CommonHelper.GetCDTSTM(this.GetType().Namespace, count, true); ConcurrentQueueExtensions.Clear(Variable.GMQ_TASKUPDATE); try { System.Threading.Tasks.Task.Factory.StartNew(m => { var key = m as XmlModule; if (Variable.CDTSTM.Count <= 0 || key == null) { return; } while (Variable.CDTSTM[key]) { if (Variable.GMQ_TASKUPDATE.Count > 0) { dynamic data; Variable.GMQ_TASKUPDATE.TryDequeue(out data); //Command.GetInstance().Service(data); var obj = data as ProtocolQueue; var _temp = new CancellationTokenSource(); System.Threading.Tasks.Task.Factory.StartNew(n => { var model = n as ProtocolQueue; var command = new Command(); if (model != null) { command.Service(model); } command.Dispose(); _temp.Cancel(); }, obj, _temp.Token); } //else Thread.Sleep(1); } CommonHelper.GetCDTSTMRemove(this.GetType().Namespace, count); _token.Cancel(); }, _module, _token.Token); } catch (Exception ex) { XTrace.WriteException(ex); Start(count); } }
/// <summary>模块启动</summary> public void Start(int count) { #if DEBUG XTrace.WriteLine("进入竞技场模块 当前计数{0}", count); #endif DisplayGlobal.log.Write(string.Format("进入竞技场模块 当前计数{0}", count)); _token = new CancellationTokenSource(); var _module = CommonHelper.GetCDTSTM(this.GetType().Namespace, count, true); ConcurrentQueueExtensions.Clear(Variable.GMQ_ARENA); try { Task.Factory.StartNew(m => { var key = m as XmlModule; while (Variable.CDTSTM.Count > 0 && key != null && Variable.CDTSTM[key]) { if (Variable.GMQ_ARENA.Count > 0) { dynamic data; Variable.GMQ_ARENA.TryDequeue(out data); //Command.GetInstance().Service(data); var obj = data as ProtocolQueue; var _temp = new CancellationTokenSource(); Task.Factory.StartNew(n => { var model = n as ProtocolQueue; Command.GetInstance().Service(model); _temp.Cancel(); }, obj, _temp.Token); } //else Thread.Sleep(1); } CommonHelper.GetCDTSTMRemove(this.GetType().Namespace, count); _token.Cancel(); }, _module, _token.Token); } catch { Start(count); } }
/// <summary>模块启动</summary> public void Start(int count) { #if DEBUG XTrace.WriteLine("进入API模块 当前计数{0}", count); #endif DisplayGlobal.log.Write(string.Format("进入API模块 当前计数{0}", count)); _token = new CancellationTokenSource(); var _module = CommonHelper.GetCDTSTM(this.GetType().Namespace, count, true); ConcurrentQueueExtensions.Clear(Variable.GMQ_API); try { Task.Factory.StartNew(m => { var key = m as XmlModule; if (Variable.CDTSTM.Count <= 0 || key == null) { return; } while (Variable.CDTSTM[key]) { if (Variable.GMQ_API.Count > 0) { dynamic data; Variable.GMQ_API.TryDequeue(out data); Command.GetInstance().Service(data); } else { Thread.Sleep(1); } } CommonHelper.GetCDTSTMRemove(this.GetType().Namespace, count); _token.Cancel(); }, _module, _token.Token); } catch { Start(count); } }
public void Dispose() { LoggerExtensions.LogTrace(_logger, "Disposing", Array.Empty <object>()); _workLoopCancellationTokenSource?.Cancel(); ConcurrentQueueExtensions.Clear(_queue); }