本文整理汇总了C#中ISubscription.UnsetQueued方法的典型用法代码示例。如果您正苦于以下问题:C# ISubscription.UnsetQueued方法的具体用法?C# ISubscription.UnsetQueued怎么用?C# ISubscription.UnsetQueued使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISubscription
的用法示例。
在下文中一共展示了ISubscription.UnsetQueued方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PumpImplAsync
private void PumpImplAsync(Task workTask, ISubscription subscription, TaskCompletionSource<object> taskCompletionSource)
{
// Async path
workTask.ContinueWith(task =>
{
bool moreWork = subscription.UnsetQueued();
_counters.MessageBusBusyWorkers.RawValue = Interlocked.Decrement(ref _busyWorkers);
Debug.Assert(_busyWorkers >= 0, "The number of busy workers has somehow gone negative");
if (task.IsFaulted)
{
Trace.TraceEvent(TraceEventType.Error, 0, "Work failed for " + subscription.Identity + ": " + task.Exception.GetBaseException());
}
if (moreWork && !task.IsFaulted)
{
PumpImpl(taskCompletionSource, subscription);
}
else
{
// Don't reference the subscription anymore
subscription = null;
PumpImpl(taskCompletionSource);
}
});
}
示例2: PumpImplAsync
private void PumpImplAsync(Task workTask, ISubscription subscription, TaskCompletionSource<object> taskCompletionSource)
{
// Async path
workTask.ContinueWith(task =>
{
subscription.UnsetQueued();
_counters.MessageBusBusyWorkers.RawValue = Interlocked.Decrement(ref _busyWorkers);
Debug.Assert(_busyWorkers >= 0, "The number of busy workers has somehow gone negative");
if (task.IsFaulted)
{
taskCompletionSource.TrySetException(task.Exception);
}
else
{
PumpImpl(taskCompletionSource);
}
});
}
示例3: 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);
}
}
示例4: PumpImpl
public void PumpImpl(TaskCompletionSource<object> taskCompletionSource, ISubscription subscription = null)
{
Process:
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 (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);
}
subscription = _queue.Dequeue();
}
}
_counters.MessageBusBusyWorkers.RawValue = Interlocked.Increment(ref _busyWorkers);
Task workTask = subscription.WorkAsync();
if (workTask.IsCompleted)
{
try
{
workTask.Wait();
goto Process;
}
catch (Exception ex)
{
taskCompletionSource.TrySetException(ex);
}
finally
{
if (!subscription.UnsetQueued())
{
// 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);
}
}