/// <summary> /// 移除一个任务 /// </summary> /// <param name="task">被移除的任务</param> internal bool RemoveTask(ConnectionTask task) { bool result; lock (taskList) { result = taskList.Remove(task); } if (result) { string LogMsg = string.Format("协议“{0}”中“{1}”任务已结束。", task.GetRelatedProtocol().Local.ToString(), task.Name); Console.WriteLine(LogMsg); } return(result); }
/// <summary> /// 移除一个任务 /// </summary> /// <param name="task">被移除的任务</param> internal bool RemoveTask(ConnectionTask task) { bool result; lock (taskListBlocking) { ConnectionTask connectionTask; result = taskListBlocking.TryTake(out connectionTask, NetworkConstants.DefaultTaskInterval, task.cancellationToken); } if (result) { string LogMsg = string.Format("协议“{0}”中“{1}”任务已结束。", task.GetRelatedProtocol().Local.ToString(), task.Name); Console.WriteLine(LogMsg); } return(result); }
/// <summary> /// 给规约增加任务 /// </summary> /// <param name="task">要添加的任务。</param> internal void AddTask(ConnectionTask task) { if (task == null) { return; } lock (taskListBlocking) { if (!taskListBlocking.Contains(task)) { if (task.GetRelatedProtocol() == null) { task.SetRelatedProtocol(this.relatedProtocol); } taskListBlocking.Add(task, task.cancellationToken); //((EventWaitHandle)this.relatedProtocol.protocolEvents[(int)ProtocolEvents.TaskArrived]).Set(); string LogMsg = string.Format("协议“{0}”增加了一个“{1}”任务。", "未定义协议名称", task.Name); } } }