本文整理汇总了C#中ISubscription.Work方法的典型用法代码示例。如果您正苦于以下问题:C# ISubscription.Work方法的具体用法?C# ISubscription.Work怎么用?C# ISubscription.Work使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISubscription
的用法示例。
在下文中一共展示了ISubscription.Work方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PumpImpl
private void PumpImpl(TaskCompletionSource<object> taskCompletionSource, ISubscription subscription = null)
{
Process:
// If we were doing work before and now we've been disposed just kill this worker early
if (_disposed)
{
taskCompletionSource.TrySetResult(null);
return;
}
Debug.Assert(_allocatedWorkers <= _maxWorkers, "How did we pass the max?");
// If we're withing the acceptable limit of idleness, just keep running
int idleWorkers = _allocatedWorkers - _busyWorkers;
if (subscription != null || idleWorkers <= _maxIdleWorkers)
{
// We already have a subscription doing work so skip the queue
if (subscription == null)
{
lock (_queue)
{
while (_queue.Count == 0)
{
Monitor.Wait(_queue);
// When disposing, all workers are pulsed so that they can quit
// if they're waiting for things to do (idle)
if (_disposed)
{
taskCompletionSource.TrySetResult(null);
return;
}
}
subscription = _queue.Dequeue();
}
}
_counters.MessageBusBusyWorkers.RawValue = Interlocked.Increment(ref _busyWorkers);
Task workTask = subscription.Work();
if (workTask.IsCompleted)
{
try
{
workTask.Wait();
goto Process;
}
catch (Exception ex)
{
Trace.TraceEvent(TraceEventType.Error, 0, "Work failed for " + subscription.Identity + ": " + ex.GetBaseException());
goto Process;
}
finally
{
if (!subscription.UnsetQueued() || workTask.IsFaulted)
{
// If we don't have more work to do just make the subscription null
subscription = null;
}
_counters.MessageBusBusyWorkers.RawValue = Interlocked.Decrement(ref _busyWorkers);
Debug.Assert(_busyWorkers >= 0, "The number of busy workers has somehow gone negative");
}
}
else
{
PumpImplAsync(workTask, subscription, taskCompletionSource);
}
}
else
{
taskCompletionSource.TrySetResult(null);
}
}