private bool TryTake(out ScheduledWork scheduledWork) { lock (_queue) { while (_queue.Count == 0) { if (_status == Status.ShuttingDown) { _status = Status.ShutDown; scheduledWork = default(ScheduledWork); return(false); } Monitor.Wait(_queue); } if (_status == Status.ShuttingDown && _timeSinceShutdown.Elapsed > _shutdownTimeout) { _status = Status.ShutDown; throw ErrorAndGetExceptionForShutdownTimeout(); } scheduledWork = _queue.Dequeue(); } return(true); }
private void AddWork(ScheduledWork work) { lock (_queue) { if (status == Status.ShutDown) { throw CreateInvalidWhenShutDownException(); } _queue.Enqueue(work); Monitor.Pulse(_queue); } }
private void QueueWork(ScheduledWork work) { // TODO: Use a binary-search for finding upper-bound index to insert new item var index = _works.FindIndex(w => w.Time > work.Time); if (index == -1) { index = _works.Count; } _works.Insert(index, work); if (index == 0 && _inProcessingWork == false) { ActionScheduled?.Invoke(work.Time - GetTime(), ProcessWork); } }
private void AddWork(ScheduledWork work) { lock (_queue) { switch (_status) { case Status.ShuttingDown: if (_timeSinceShutdown.Elapsed < _shutdownTimeout) { break; } goto case Status.ShutDown; case Status.ShutDown: throw ErrorAndGetExceptionForShutdownTimeout(); } _queue.Enqueue(work); Monitor.Pulse(_queue); } }
private bool TryTake(out ScheduledWork scheduledWork) { lock (_queue) { for (;;) { if (status == Status.ShutDown) { scheduledWork = default(ScheduledWork); return(false); } if (_queue.Count != 0) { break; } Monitor.Wait(_queue); } scheduledWork = _queue.Dequeue(); } return(true); }