當前位置: 首頁>>代碼示例>>C#>>正文


C# AsyncQueue類代碼示例

本文整理匯總了C#中AsyncQueue的典型用法代碼示例。如果您正苦於以下問題:C# AsyncQueue類的具體用法?C# AsyncQueue怎麽用?C# AsyncQueue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AsyncQueue類屬於命名空間,在下文中一共展示了AsyncQueue類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的AsyncQueue類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。