public void Start() { ICollection <ThreadPoolDelegate> handlers = null; Monitor.Enter(_syncLock); try { if (_hasBeenStarted) { throw new InvalidOperationException("Pool has already been started."); } _hasBeenStarted = true; /* * Check to see if there were already items posted to the queue * before Start was called. If so, reset their timestamps to * the current time. */ if (_requestQueue.Count > 0) { ResetWorkRequestTimes(); } for (int n = 0; n < _initialThreadCount; n++) { ThreadWrapper thread = new ThreadWrapper(this, true, _threadPriority, string.Format("{0} (static)", _threadPoolName)); thread.Start(); } if (Started != null) { Delegate[] delegates = Started.GetInvocationList(); handlers = new List <ThreadPoolDelegate>(delegates.Length); foreach (ThreadPoolDelegate handler in delegates) { if (handler != null) { handlers.Add(handler); } } } } finally { Monitor.Exit(_syncLock); } if (handlers != null) { foreach (ThreadPoolDelegate handler in handlers) { handler(); } } }
/// <summary> /// Start or restarts the countdown. /// </summary> /// <param name="countdownTime">In ms.</param> /// <param name="reportProgressTime">In ms. Min 100</param> public void Start(int countdownTime, int reportProgressTime = 1000) { CountdownTime = countdownTime; ReportProgressTime = reportProgressTime; if (_tmr != null) { Stop(); } _tmr = new Timer(reportProgressTime); _tmr.Elapsed += _tmr_Elapsed; _tmr.Start(); if (Started != null) { var invocationList = Started.GetInvocationList(); Parallel.For(0, invocationList.Length, (i) => { (invocationList[i] as EventHandler).Invoke(this, null); }); } }