本文整理汇总了C#中AsyncQueue类的典型用法代码示例。如果您正苦于以下问题:C# AsyncQueue类的具体用法?C# AsyncQueue怎么用?C# AsyncQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AsyncQueue类属于命名空间,在下文中一共展示了AsyncQueue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: DequeueAsync_before_Enqueue
public void DequeueAsync_before_Enqueue()
{
var queue = new AsyncQueue<string>();
var task = queue.DequeueAsync().AssertNotCompleted();
queue.Enqueue("A");
task.AssertResult("A");
}
开发者ID:timothy-shields,项目名称:async-data-structures,代码行数:7,代码来源:AsyncQueueTests.cs
示例2: TryEnqueueAfterComplete
public void TryEnqueueAfterComplete()
{
var queue = new AsyncQueue<int>();
Assert.True(queue.TryEnqueue(42));
queue.Complete();
Assert.False(queue.TryEnqueue(42));
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:7,代码来源:AsyncQueueTests.cs
示例3: MultiServerCluster
// constructors
public MultiServerCluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IEventSubscriber eventSubscriber)
: base(settings, serverFactory, eventSubscriber)
{
Ensure.IsGreaterThanZero(settings.EndPoints.Count, "settings.EndPoints.Count");
if (settings.ConnectionMode == ClusterConnectionMode.Standalone)
{
throw new ArgumentException("ClusterConnectionMode.StandAlone is not supported for a MultiServerCluster.");
}
if (settings.ConnectionMode == ClusterConnectionMode.Direct)
{
throw new ArgumentException("ClusterConnectionMode.Direct is not supported for a MultiServerCluster.");
}
_monitorServersCancellationTokenSource = new CancellationTokenSource();
_serverDescriptionChangedQueue = new AsyncQueue<ServerDescriptionChangedEventArgs>();
_servers = new List<IClusterableServer>();
_state = new InterlockedInt32(State.Initial);
_replicaSetName = settings.ReplicaSetName;
eventSubscriber.TryGetEventHandler(out _closingEventHandler);
eventSubscriber.TryGetEventHandler(out _closedEventHandler);
eventSubscriber.TryGetEventHandler(out _openingEventHandler);
eventSubscriber.TryGetEventHandler(out _openedEventHandler);
eventSubscriber.TryGetEventHandler(out _addingServerEventHandler);
eventSubscriber.TryGetEventHandler(out _addedServerEventHandler);
eventSubscriber.TryGetEventHandler(out _removingServerEventHandler);
eventSubscriber.TryGetEventHandler(out _removedServerEventHandler);
}
开发者ID:kay-kim,项目名称:mongo-csharp-driver,代码行数:29,代码来源:MultiServerCluster.cs
示例4: Dequeue_should_return_an_uncompleted_task_when_no_items_exist
public void Dequeue_should_return_an_uncompleted_task_when_no_items_exist()
{
var subject = new AsyncQueue<int>();
var result = subject.DequeueAsync(CancellationToken.None);
result.IsCompleted.Should().BeFalse();
}
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:7,代码来源:AsyncQueueTests.cs
示例5: AnalyzerDriver
/// <summary>
/// Create an analyzer driver.
/// </summary>
/// <param name="analyzers">The set of analyzers to include in the analysis</param>
/// <param name="options">Options that are passed to analyzers</param>
/// <param name="cancellationToken">a cancellation token that can be used to abort analysis</param>
/// <param name="continueOnAnalyzerException">Delegate which is invoked when an analyzer throws an exception.
/// If a non-null delegate is provided and it returns true, then the exception is handled and converted into a diagnostic and driver continues with other analyzers.
/// Otherwise if it returns false, then the exception is not handled by the driver.
/// If null, then the driver always handles the exception.
/// </param>
protected AnalyzerDriver(ImmutableArray<IDiagnosticAnalyzer> analyzers, AnalyzerOptions options, CancellationToken cancellationToken, Func<Exception, IDiagnosticAnalyzer, bool> continueOnAnalyzerException = null)
{
this.CompilationEventQueue = new AsyncQueue<CompilationEvent>();
this.DiagnosticQueue = new AsyncQueue<Diagnostic>();
this.addDiagnostic = GetDiagnosticSinkWithSuppression();
this.analyzerOptions = options;
Func<Exception, IDiagnosticAnalyzer, bool> defaultExceptionHandler = (exception, analyzer) => true;
this.continueOnAnalyzerException = continueOnAnalyzerException ?? defaultExceptionHandler;
// start the first task to drain the event queue. The first compilation event is to be handled before
// any other ones, so we cannot have more than one event processing task until the first event has been handled.
initialWorker = Task.Run(async () =>
{
try
{
await InitialWorkerAsync(analyzers, continueOnAnalyzerException, cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
// If creation is cancelled we had better not use the driver any longer
this.Dispose();
}
});
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:36,代码来源:AnalyzerDriver.cs
示例6: Enqueue
public void Enqueue()
{
var queue = new AsyncQueue<int>();
queue.Enqueue(42);
var task = queue.DequeueAsync();
Assert.True(task.IsCompleted);
Assert.Equal(42, task.Result);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:8,代码来源:AsyncQueueTests.cs
示例7: Dequeue_should_complete_when_an_item_is_added_to_the_queue
public void Dequeue_should_complete_when_an_item_is_added_to_the_queue()
{
var subject = new AsyncQueue<int>();
var result = subject.DequeueAsync(CancellationToken.None);
subject.Enqueue(10);
result.Result.Should().Be(10);
}
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:8,代码来源:AsyncQueueTests.cs
示例8: DequeueThenEnqueue
public async Task DequeueThenEnqueue()
{
var queue = new AsyncQueue<int>();
var task = queue.DequeueAsync();
Assert.False(task.IsCompleted);
queue.Enqueue(13);
Assert.Equal(13, await task.ConfigureAwait(false));
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:8,代码来源:AsyncQueueTests.cs
示例9: AlarmAdapter
/// <summary>
/// Creates a new instance of the <see cref="AlarmAdapter"/>.
/// </summary>
public AlarmAdapter()
{
m_measurementQueue = new AsyncQueue<IEnumerable<IMeasurement>>()
{
ProcessItemFunction = ProcessMeasurements
};
m_measurementQueue.ProcessException += m_measurementQueue_ProcessException;
}
开发者ID:avs009,项目名称:gsf,代码行数:12,代码来源:AlarmAdapter.cs
示例10: TryEnqueueAfterPromisingNotTo
public void TryEnqueueAfterPromisingNotTo()
{
var queue = new AsyncQueue<int>();
Assert.True(queue.TryEnqueue(42));
queue.PromiseNotToEnqueue();
Assert.Throws(typeof(InvalidOperationException), () => {
queue.TryEnqueue(42);
});
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:9,代码来源:AsyncQueueTests.cs
示例11: VerifyEvents
internal static void VerifyEvents(AsyncQueue<CompilationEvent> queue, params string[] expectedEvents)
{
var expected = new HashSet<string>();
foreach (var s in expectedEvents)
{
if (!expected.Add(s))
{
Console.WriteLine("Expected duplicate " + s);
}
}
var actual = ArrayBuilder<CompilationEvent>.GetInstance();
while (queue.Count > 0 || !queue.IsCompleted)
{
var te = queue.DequeueAsync();
Assert.True(te.IsCompleted);
actual.Add(te.Result);
}
bool unexpected = false;
foreach (var a in actual)
{
var eventString = a.ToString();
if (!expected.Remove(eventString))
{
if (!unexpected)
{
Console.WriteLine("UNEXPECTED EVENTS:");
unexpected = true;
}
Console.WriteLine(eventString);
}
}
if (expected.Count != 0)
{
Console.WriteLine("MISSING EVENTS:");
}
foreach (var e in expected)
{
Console.WriteLine(e);
}
if (unexpected || expected.Count != 0)
{
bool first = true;
Console.WriteLine("ACTUAL EVENTS:");
foreach (var e in actual)
{
if (!first)
{
Console.WriteLine(",");
}
first = false;
Console.Write("\"" + e.ToString() + "\"");
}
Console.WriteLine();
Assert.True(false);
}
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:57,代码来源:CompilationEventTests.cs
示例12: CancelAllDequeue
public void CancelAllDequeue()
{
var queue = new AsyncQueue<string>();
var tasks = Enumerable.Range(0, 3).Select(_ => queue.DequeueAsync()).ToList();
queue.CancelAllDequeue().Dispose();
foreach (var task in tasks)
{
task.AssertCanceled();
}
}
开发者ID:timothy-shields,项目名称:async-data-structures,代码行数:10,代码来源:AsyncQueueTests.cs
示例13: CompleteAllDequeue
public void CompleteAllDequeue()
{
var queue = new AsyncQueue<string>();
var tasks = Enumerable.Range(0, 3).Select(_ => queue.DequeueAsync()).ToList();
queue.CompleteAllDequeue("X").Dispose();
foreach (var task in tasks)
{
task.AssertResult("X");
}
}
开发者ID:timothy-shields,项目名称:async-data-structures,代码行数:10,代码来源:AsyncQueueTests.cs
示例14: Count_nonempty
public void Count_nonempty()
{
var queue = new AsyncQueue<string>();
queue.Enqueue("A");
queue.Enqueue("B");
queue.Enqueue("C");
queue.Enqueue("D");
Assert.IsTrue(queue.TryDequeue());
Assert.AreEqual(3, queue.Count);
}
开发者ID:timothy-shields,项目名称:async-data-structures,代码行数:10,代码来源:AsyncQueueTests.cs
示例15: DequeueAsync_canceled_after_completion
public void DequeueAsync_canceled_after_completion()
{
var queue = new AsyncQueue<string>();
queue.Enqueue("A");
using (var cts = new CancellationTokenSource())
{
var task = queue.DequeueAsync(cts.Token);
cts.Cancel();
task.AssertResult("A");
}
}
开发者ID:timothy-shields,项目名称:async-data-structures,代码行数:11,代码来源:AsyncQueueTests.cs
示例16: DequeueAll_should_dequeue_all_items
public void DequeueAll_should_dequeue_all_items(int n)
{
var subject = new AsyncQueue<int>();
for (var i = 0; i < n; i++)
{
subject.Enqueue(i);
}
var count = subject.DequeueAll().Count();
count.Should().Be(n);
}
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:11,代码来源:AsyncQueueTests.cs
示例17: Items_should_be_dequeued_in_the_order_they_were_enqueued_2
public void Items_should_be_dequeued_in_the_order_they_were_enqueued_2()
{
var subject = new AsyncQueue<int>();
var result = subject.DequeueAsync(CancellationToken.None);
var result2 = subject.DequeueAsync(CancellationToken.None);
subject.Enqueue(10);
subject.Enqueue(11);
result.Result.Should().Be(10);
result2.Result.Should().Be(11);
}
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:11,代码来源:AsyncQueueTests.cs
示例18: ConsumeItems
private async Task ConsumeItems(
AsyncQueue<int> inputQueue,
ConcurrentBag<int> outputItems,
CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
int consumedItem = await inputQueue.DequeueAsync(cancellationToken);
outputItems.Add(consumedItem);
}
}
开发者ID:sunnyc7,项目名称:PowerShellEditorServices,代码行数:11,代码来源:AsyncQueueTests.cs
示例19: MultiServerCluster
// constructors
public MultiServerCluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IClusterListener listener)
: base(settings, serverFactory, listener)
{
Ensure.IsGreaterThanZero(settings.EndPoints.Count, "settings.EndPoints.Count");
_monitorServersCancellationTokenSource = new CancellationTokenSource();
_serverDescriptionChangedQueue = new AsyncQueue<ServerDescriptionChangedEventArgs>();
_servers = new List<IClusterableServer>();
_state = new InterlockedInt32(State.Initial);
_replicaSetName = settings.ReplicaSetName;
}
开发者ID:Nakro,项目名称:mongo-csharp-driver,代码行数:12,代码来源:MultiServerCluster.cs
示例20: MetricImporter
/// <summary>
/// Initializes a new instance of the <see cref="MetricImporter"/> class.
/// </summary>
public MetricImporter()
{
m_fileProcessQueue = new AsyncQueue<string>();
m_fileProcessQueue.ProcessItemFunction = ProcessFile;
m_fileProcessQueue.ProcessException += m_fileProcessQueue_ProcessException;
m_columns = new Dictionary<string, int>(StringComparer.CurrentCultureIgnoreCase);
m_columnMappings = new Dictionary<int, IMeasurement>();
m_inputInterval = 5.0D;
m_measurementsPerInterval = 5;
m_skipRows = 4;
m_timestampFormat = "dd-MMM-yyyy HH:mm:ss.fff";
// Set minimum timer resolution to one millisecond to improve timer accuracy
PrecisionTimer.SetMinimumTimerResolution(1);
}
开发者ID:rmc00,项目名称:gsf,代码行数:20,代码来源:MetricImporter.cs
注:本文中的AsyncQueue类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论