當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。