/// <summary> /// Schedule an item for processing, potentially also starting the background process if it is not running. /// </summary> /// <remarks>If an item is already scheduled, it won't be added again, but the background task will still /// start if <paramref name="startProcess"/> is true.</remarks> /// <param name="item">An item that will be scheduled.</param> /// <param name="startProcess">A value indicating whether the background should be started if it is not running already.</param> public void Schedule(T item, bool startProcess = true) { bool scheduled = false; lock (queueLock) { if (queueSet.Add(item)) { processingQueue.Enqueue(item); scheduled = true; } } if (scheduled) { Interlocked.Increment(ref totalScheduledCount); Scheduled?.Invoke(this, BuildEventArgs()); } if (startProcess && !BackgroundTaskRunning) { StartBackgroundTask(); } }
public void Schedule(Func <TInput> inputsFactory) { OnSchedule(inputsFactory); Scheduled?.Invoke(this, new EventArgs()); }
private void OnScheduled() { Scheduled?.Invoke(this, EventArgs.Empty); }