/// <inheritdoc/> public void Start(bool isClearData) { if (IsRunning) { return; } #region 如果要求先清空資料 if (isClearData) { lock (queueData) { queueData.Clear(); } } #endregion #region 初始化並執行 lock (lock_DataWorker) { IsRunning = true; workerFlag.Clear(); workers.Clear(); for (int idx = 0; idx < WorkerCount; ++idx) { Thread newWorker = new Thread(WokerJob); ManualResetEvent newFlag = new ManualResetEvent(false); workerFlag.Enqueue(newFlag); newWorker.IsBackground = true; newWorker.Start(newFlag); workers.Add(newWorker); } // 如果已有資料就開始啟動 lock (queueData) { if (queueData.Count > 0) { Dispatch(); } } } #endregion }
public void Start(bool isClearData) { if (IsRunning) { return; } isStop = false; #region 如果要求先清空資料 if (isClearData) { lock (queueData) { queueData.Clear(); } } #endregion #region 初始化並執行 lock (lock_DataWorker) { IsRunning = true; workerFlag.Clear(); for (int idx = 0; idx < WorkerCount; ++idx) { ManualResetEvent newFlag = new ManualResetEvent(false); workerFlag.Enqueue(newFlag); } // 如果已有資料就開始啟動 lock (queueData) { if (queueData.Count > 0) { Dispatch(); } } } #endregion }
/// <inheritdoc/> public void Clear() { try { rwLock.EnterWriteLock(); try { inContainer.Clear(); outContainer.Clear(); } finally { rwLock.ExitWriteLock(); } } catch (Exception exp) { throw (new TimeoutException("SwitchContainer::Clear() timeout", exp)); } }