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


C# Task.SelectMany方法代码示例

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


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

示例1: AppendCurrentIteration

 void AppendCurrentIteration(IterationView iteration, List<int> projects, Func<CardView, bool> cardFilter)
 {
     var tasks = new Task<List<CardView>>[projects.Count];
     for(var i = 0; i != projects.Count; ++i) {
         tasks[i] = CardsForCurrentIteration(projects[i]);
     }
     iteration.AddRange(tasks.SelectMany(x => x.Result).Where(cardFilter), x => x.CurrentState);
 }
开发者ID:drunkcod,项目名称:CardWall,代码行数:8,代码来源:ProjectsController.cs

示例2: SendAsyncShouldHandleHighVolumeOfMessages

        public void 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<List<ProduceResponse>>[amount];

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

                var results = tasks.SelectMany(x => x.Result).ToList();

                //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.Error != 0), Is.False, "Should not have received any results as failures.");
            }
        }
开发者ID:jsifantu,项目名称:kafka-net,代码行数:21,代码来源:ProducerConsumerIntegrationTests.cs

示例3: GetMedicines

        private List<MedicineRaw> GetMedicines()
        {
            string page1 = this.GetResponseTextWithCache(1);
            var document1 = new HtmlDocument();
            document1.LoadHtml(page1);
            HtmlNode linkFim = document1.DocumentNode.SelectSingleNode("//a[contains(text(), 'Fim')]");
            string hrefLinkFim = linkFim.GetAttributeValue("href", "");
            int regexCountPages = int.Parse(Regex.Match(hrefLinkFim, @"(?<=&pagina=)\d+").Value);

            var listTasks = new Task<List<MedicineRaw>>[regexCountPages];
            for (int pagina = 0; pagina < regexCountPages; pagina++)
                listTasks[pagina] = new Task<List<MedicineRaw>>(this.GetItems, pagina + 1);

            foreach (var eachTask in listTasks)
                eachTask.Start();

            Task.WaitAll(listTasks.OfType<Task>().ToArray());

            List<MedicineRaw> medicines = listTasks.SelectMany(t => t.Result).ToList();

            return medicines;
        }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:22,代码来源:AnvisaLeafletHelper.cs

示例4: SendAsyncShouldHandleHighVolumeOfMessages

        public void SendAsyncShouldHandleHighVolumeOfMessages(int amount, int maxAsync)
        {
            var tasks = new Task<List<ProduceResponse>>[amount];
            var producer = new Producer(_router, maxAsync);

            for (var i = 0; i < amount; i++)
            {
                tasks[i] = producer.SendMessageAsync("LoadTest", new Message[] { new Message { Value = Guid.NewGuid().ToString() } });
            }

            var results = tasks.SelectMany(x => x.Result).ToList();

            Assert.That(results.Count, Is.EqualTo(amount));
            Assert.That(results.Any(x => x.Error != 0), Is.False);
        }
开发者ID:jmucza,项目名称:kafka-net,代码行数:15,代码来源:ProducerConsumerTests.cs

示例5: Run

        private static void Run(Uri uriAddress, int runCount, int parallelCount)
        {
            var tasks = new Task<IEnumerable<HttpResult>>[parallelCount];

            var stopwatch = Stopwatch.StartNew();
            for (var i = 0; i < parallelCount; i++)
            {
                tasks[i] = Task.Factory.StartNew(() => HttpGet(uriAddress, runCount));
            }
            Task.WaitAll(tasks);

            var totalTime = stopwatch.Elapsed;

            PrintResults(totalTime, parallelCount, tasks.SelectMany(t => t.Result).ToArray());
        }
开发者ID:donatasm,项目名称:WCF-Performance-Tuning,代码行数:15,代码来源:Program.cs

示例6: is_thread_safe

        public void is_thread_safe()
        {
            var tasks = new Task<List<int>>[] {startThread(), startThread(), startThread(), startThread(), startThread(), startThread()};

            Task.WaitAll(tasks);

            var all = tasks.SelectMany(x => x.Result).ToArray();

            all.GroupBy(x => x).Any(x => x.Count() > 1).ShouldBeFalse();

            all.Distinct().Count().ShouldBe(tasks.Length * 1000);
        }
开发者ID:danielmarbach,项目名称:marten,代码行数:12,代码来源:HiLoSequenceTests.cs


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