本文整理汇总了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);
}
示例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.");
}
}
示例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;
}
示例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);
}
示例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());
}
示例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);
}