本文整理汇总了C#中AsyncQueue.Complete方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncQueue.Complete方法的具体用法?C# AsyncQueue.Complete怎么用?C# AsyncQueue.Complete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncQueue
的用法示例。
在下文中一共展示了AsyncQueue.Complete方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryEnqueueAfterComplete
public void TryEnqueueAfterComplete()
{
var queue = new AsyncQueue<int>();
Assert.True(queue.TryEnqueue(42));
queue.Complete();
Assert.False(queue.TryEnqueue(42));
}
示例2: DequeueThenComplete
public async Task DequeueThenComplete()
{
var queue = new AsyncQueue<int>();
var task = queue.DequeueAsync();
Assert.False(task.IsCompleted);
queue.Complete();
var threw = false;
try
{
await task.ConfigureAwait(false);
}
catch (OperationCanceledException)
{
threw = true;
}
Assert.True(threw);
}
示例3: DequeueManyThenComplete
public async Task DequeueManyThenComplete()
{
var queue = new AsyncQueue<int>();
var list = new List<Task<int>>();
for (var i = 0; i < 4; i++)
{
list.Add(queue.DequeueAsync());
}
queue.Complete();
foreach (var task in list)
{
var threw = false;
try
{
await task.ConfigureAwait(false);
}
catch (OperationCanceledException)
{
threw = true;
}
Assert.True(threw);
}
}
示例4: EnqueueAfterComplete
public void EnqueueAfterComplete()
{
var queue = new AsyncQueue<int>();
queue.Complete();
Assert.Throws(typeof(InvalidOperationException), () => queue.Enqueue(42));
}
示例5: TryDequeueAfterComplete
public async Task TryDequeueAfterComplete()
{
var queue = new AsyncQueue<int>();
queue.Enqueue(13);
queue.Complete();
await queue.WhenCompletedTask.ConfigureAwait(false);
int value;
Assert.True(queue.TryDequeue(out value));
Assert.Equal(13, value);
}
示例6: TaskCompletesAsyncWithComplete
public async Task TaskCompletesAsyncWithComplete()
{
var queue = new AsyncQueue<int>();
var tcs = new TaskCompletionSource<bool>();
var task = queue.DequeueAsync().ContinueWith(
t =>
{
tcs.Task.Wait();
return 0;
},
default(CancellationToken),
TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
queue.Complete();
Assert.False(queue.WhenCompletedTask.IsCompleted);
tcs.SetResult(true);
await queue.WhenCompletedTask.ConfigureAwait(false);
// The AsyncQueue<T>.Task property won't complete until all of the
// existing DequeueAsync values have also completed.
Assert.True(task.IsCompleted);
}
示例7: DequeueAfterCompleteWithData
public async Task DequeueAfterCompleteWithData()
{
var queue = new AsyncQueue<int>();
queue.Enqueue(42);
queue.Complete();
await queue.WhenCompletedTask.ConfigureAwait(false);
Assert.Equal(42, await queue.DequeueAsync().ConfigureAwait(false));
var threw = false;
try
{
await queue.DequeueAsync().ConfigureAwait(false);
}
catch (OperationCanceledException)
{
threw = true;
}
Assert.True(threw);
}