// interface to add a new item to the copy queue private void QueueUserWorkItem(WaitCallback callback, object state) { try { if (this.threads == null) { throw new ObjectDisposedException(GetType().Name); } if (callback == null) { throw new ArgumentNullException("callback"); } WaitQueueItem item = new WaitQueueItem(); item.Callback = callback; item.State = state; item.Context = ExecutionContext.Capture(); lock (this.queue) { this.queue.Enqueue(item); } } finally { this.workWaiting.Release(); } }
public void QueueUserWorkItem(WaitCallback callback, object state) { if (threads == null) { throw new ObjectDisposedException(GetType().Name); } if (callback == null) { throw new ArgumentNullException("callback"); } var item = new WaitQueueItem { Callback = callback, State = state, Context = ExecutionContext.Capture() }; lock (queue) queue.Enqueue(item); workWaiting.Release(); }
// method the copy threads use to copy each file private void RunWorker() { try { while (!this.timeToQuit) { WaitQueueItem item = null; lock (this.queue) { if (this.queue.Count > 0) { item = this.queue.Dequeue(); } } // only run if valid and else if means running multple times from a command line >1 or it is set to service (-1) if (item != null) { this.workingCopyThreads++; ExecutionContext.Run(item.Context, new ContextCallback(item.Callback), item.State); this.workingCopyThreads--; } else if (this.timesToRunTheWorkFinder > 1 || this.timesToRunTheWorkFinder == -1) { this.workWaiting.WaitOne(this.copyConfig.SleepBetweenBatchesMs); } } } catch (Exception ex) { VRASLogEvent.LogMesage( VRASLogEvent.EventLogName, String.Format("Error with copy thread: {0}", ex.Message), System.Diagnostics.EventLogEntryType.Error, Convert.ToInt32(VRAS.VRASLogEvent.EventIDs.FileCopyError), VRASLogEvent.EventSourceDefault); } }
public void QueueUserWorkItem(WaitCallback callback, object state) { if (threads == null) throw new ObjectDisposedException(GetType().Name); if (callback == null) throw new ArgumentNullException("callback"); var item = new WaitQueueItem { Callback = callback, State = state, Context = ExecutionContext.Capture() }; lock (queue) queue.Enqueue(item); workWaiting.Release(); }