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