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


C# Task.ToArray方法代码示例

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


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

示例1: ShouldSend100MessagesMultiThreadedWithTransactions

        public void ShouldSend100MessagesMultiThreadedWithTransactions()
        {
            int count = 100;
            var stop = Stopwatch.StartNew();
            using (var provider = new XmsProducerProvider(true))
            {
                var taskFactory = new TaskFactory();
                var tasks = new Task[count];

                for (int i = 0; i < count; i++)
                {
                    tasks[i] = taskFactory.StartNew(
                        () =>
                        {
                            using(var scope = new TransactionScope(TransactionScopeOption.Required))
                            {
                                provider.SendTestMessage(destination);
                                scope.Complete();
                            }
                        });
                }
                Task.WaitAll(tasks.ToArray());
                stop.Stop();
            }
            Console.WriteLine("Sent {0} messages multi-threaded in {1}", count, stop.Elapsed);
            destination.AssertMessageCount(count);
        }
开发者ID:sasha-uk,项目名称:NServiceBus.Xms.2,代码行数:27,代码来源:XmsProducerProviderTest.cs

示例2: SendAsyncShouldHandleHighVolumeOfMessages

        public async Task SendAsyncShouldHandleHighVolumeOfMessages(int amount, int maxAsync)
        {
            using (var router = new BrokerRouter(new KafkaOptions(IntegrationConfig.IntegrationUri)))
            using (var producer = new Producer(router, maxAsync) { BatchSize = amount / 2 })
            {
                var tasks = new Task<ProduceResponse[]>[amount];

                for (var i = 0; i < amount; i++)
                {
                    tasks[i] = producer.SendMessageAsync(IntegrationConfig.IntegrationTopic,
                        new[] { new Message(Guid.NewGuid().ToString()) });
                }
                var results = await Task.WhenAll(tasks.ToArray());

                //Because of how responses are batched up and sent to servers, we will usually get multiple responses per requested message batch
                //So this assertion will never pass
                //Assert.That(results.Count, Is.EqualTo(amount));

                Assert.That(results.Any(x => x.Any(y => y.Error != 0)), Is.False,
                    "Should not have received any results as failures.");
            }
        }
开发者ID:pooyasoleimany,项目名称:KafkaNetClient,代码行数:22,代码来源:ProducerConsumerIntegrationTests.cs


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