本文整理匯總了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);
}