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


C# ConcurrentQueue.Distinct方法代码示例

本文整理汇总了C#中ConcurrentQueue.Distinct方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentQueue.Distinct方法的具体用法?C# ConcurrentQueue.Distinct怎么用?C# ConcurrentQueue.Distinct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConcurrentQueue的用法示例。


在下文中一共展示了ConcurrentQueue.Distinct方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SemaphoreMultiplex

        static void SemaphoreMultiplex() 
        {
            counter = 0;
            Semaphore multiple = new Semaphore(0, 10);
            multiple.Release();
            ConcurrentQueue<int> answer = new ConcurrentQueue<int>();

            //multiple.
            Random ex = new Random();
            Thread[] array = new Thread[50];
            for (int i = 0; i < 50; i++) 
            {
                array[i] = new Thread(
                        () =>
                        {
                            multiple.WaitOne();
                            counter = 1 + counter;
                            Thread.Sleep(ex.Next(67));
                            multiple.Release();
                            answer.Enqueue(counter);
                        }
                    );
                array[i].Start();
               
            }
            foreach (var t in array) 
            {
                t.Join();
            }

            var s = answer.Distinct();
            foreach (var t in answer)
            {
                Console.WriteLine("count {0} and t {1}", t, answer.Count());
            };
        }
开发者ID:edwardt,项目名称:KeyConcepts,代码行数:36,代码来源:Program.cs

示例2: Uses_Same_Thread_For_Multiple_Actions

        public void Uses_Same_Thread_For_Multiple_Actions()
        {
            var threads = new ConcurrentQueue<Thread>();

            var tasks = Enumerable.Range(0, 5000).Select(i => this.Execute(() => threads.Enqueue(Thread.CurrentThread))).ToArray();
            Task.WaitAll(tasks);

            Assert.AreEqual(5000, threads.Count);
            Assert.AreEqual(1, threads.Distinct().Count());
        }
开发者ID:tuyndv,项目名称:journeyofcode,代码行数:10,代码来源:SingleThreadTaskSchedulerTests.cs

示例3: Notifier_should_retry_sending_health_updates_in_case_of_exceptions

        public async Task Notifier_should_retry_sending_health_updates_in_case_of_exceptions()
        {
            var endpointId = Guid.NewGuid();
            SetupEndpointRegistration(endpointId);
            var checkInterval = TimeSpan.FromMilliseconds(127);

            SetupHealthCheckInterval(checkInterval);
            var minRepeats = 10;
            var countdown = new AsyncCountdown("update", minRepeats);
            var updates = new ConcurrentQueue<HealthUpdate>();

            _mockClient
                .Setup(c => c.SendHealthUpdateAsync(endpointId, AuthenticationToken, It.IsAny<HealthUpdate>(), It.IsAny<CancellationToken>()))
                .Returns((Guid id, string authToken, HealthUpdate upd, CancellationToken token) =>
                {
                    updates.Enqueue(upd);
                    return _awaitableFactory
                        .Throw(new InvalidOperationException())
                        .WithCountdown(countdown)
                        .RunAsync();
                });

            using (CreateNotifier())
                await countdown.WaitAsync(TestMaxTime);

            int expectedSeconds = 1;
            for (int i = 0; i < minRepeats; ++i)
            {
                _mockTimeCoordinator.Verify(c => c.Delay(TimeSpan.FromSeconds(expectedSeconds), It.IsAny<CancellationToken>()));
                expectedSeconds = Math.Min(expectedSeconds *= 2, MaxEndpointNotifierRetryDelayInSecs);
            }

            _mockTimeCoordinator.Verify(c => c.Delay(checkInterval, It.IsAny<CancellationToken>()), Times.Once);

            Assert.Equal(1, updates.Distinct().Count());
        }
开发者ID:wongatech,项目名称:HealthMonitoring,代码行数:36,代码来源:EndpointNotifierTests.cs

示例4: ShouldSupportUsingOneGeneratorFromMultipleThreads

        public void ShouldSupportUsingOneGeneratorFromMultipleThreads()
        {
            // Arrange
            var account = CloudStorageAccount.DevelopmentStorageAccount;
            using (var testScope = new TestScope(account))
            {
                var store = new BlobOptimisticDataStore(account, testScope.ContainerName);
                var generator = new UniqueIdGenerator(store) { BatchSize = 1000 };
                const int testLength = 10000;

                // Act
                var generatedIds = new ConcurrentQueue<long>();
                var threadIds = new ConcurrentQueue<int>();
                var scopeName = testScope.IdScopeName;
                Parallel.For(
                    0,
                    testLength,
                    new ParallelOptions { MaxDegreeOfParallelism = 10 },
                    i =>
                    {
                        generatedIds.Enqueue(generator.NextId(scopeName));
                        threadIds.Enqueue(Thread.CurrentThread.ManagedThreadId);
                    });

                // Assert we generated the right count of ids
                Assert.AreEqual(testLength, generatedIds.Count);

                // Assert there were no duplicates
                Assert.IsFalse(generatedIds.GroupBy(n => n).Where(g => g.Count() != 1).Any());

                // Assert we used multiple threads
                var uniqueThreadsUsed = threadIds.Distinct().Count();
                if (uniqueThreadsUsed == 1)
                    Assert.Inconclusive("The test failed to actually utilize multiple threads");
            }
        }
开发者ID:cyberprune,项目名称:SnowMaker,代码行数:36,代码来源:Azure.cs


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