/// <summary> /// Queues the page view. /// </summary> /// <param name="task">The task.</param> public static void Add(IBackgroundTask task) { lock (TaskManagerLockObject) { if (_currentBackgroundTaskBatch == null) { _currentBackgroundTaskBatch = new BackgroundTaskBatch(); } _currentBackgroundTaskBatch.Add(task); if (_currentBackgroundTaskBatch.Count >= BatchSize) { var tasks = _currentBackgroundTaskBatch.GetTasks(); ThreadPool.QueueUserWorkItem(callback => { if(_processor == null) return; foreach (var item in tasks) { _processor.Process(item); } }); _currentBackgroundTaskBatch = null; } } }
/// <summary> /// Clears the queued tasks. /// </summary> public static void Clear() { if (_currentBackgroundTaskBatch != null) { _currentBackgroundTaskBatch.Clear(); _currentBackgroundTaskBatch = null; } }