当前位置: 首页>>代码示例>>C#>>正文


C# AsyncQueue.Complete方法代码示例

本文整理汇总了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));
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:7,代码来源:AsyncQueueTests.cs

示例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);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:19,代码来源:AsyncQueueTests.cs

示例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);
            }
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:25,代码来源:AsyncQueueTests.cs

示例4: EnqueueAfterComplete

 public void EnqueueAfterComplete()
 {
     var queue = new AsyncQueue<int>();
     queue.Complete();
     Assert.Throws(typeof(InvalidOperationException), () => queue.Enqueue(42));
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:6,代码来源:AsyncQueueTests.cs

示例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);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:11,代码来源:AsyncQueueTests.cs

示例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);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:24,代码来源:AsyncQueueTests.cs

示例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);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:19,代码来源:AsyncQueueTests.cs


注:本文中的AsyncQueue.Complete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。