parallel.foreach

Parallel Foreach Race Condition

六眼飞鱼酱① 提交于 2019-12-12 03:48:53
问题 i have an issue with a parallel foreach closing the connection before it finishes executing. when i had a regular foreach loop runnung it was slow but it would return everything. once i changed to a parallel foreach it is now returning about 95% of the data and terminating. below is the code that i am using: var USPostalCodes = repository.GetUSPostalCodes(); var CAPostalCodes = repository.GetCAPostalCodes(); Parallel.ForEach(spreadsheetinfo, location => { LocationData Locationdata = new

Can not use await inside a Parallel.Foreach . error :- The 'await' operator can only be used within an async lambda expression

泄露秘密 提交于 2019-12-12 00:44:03
问题 I have the following method inside my asp.net mvc-5 web application :- public async Task <List<Details>> Get() { Parallel.ForEach(resourcesinfo.operation.Details,new ParallelOptions { MaxDegreeOfParallelism = 20 }, (c) => { ResourceAccountListInfo resourceAccountListInfo = new ResourceAccountListInfo(); using (WebClient wc = new WebClient()) { string url = currentURL + "resources/" + c.RESOURCEID + "/accounts?AUTHTOKEN=" + pmtoken; string tempurl = url.Trim(); var json = await wc

VB.NET running sum in nested loop inside Parallel.for Synclock loses information

夙愿已清 提交于 2019-12-11 19:13:55
问题 Below is the best representation I have been able to develop for calculating a running sum inside a loop that's nested inside a Parallel.for loop in VB.NET (Visual Studio 2010, .NET Framework 4). Note that when showing the results in `sum' to the screen, there is a slight difference between the two sums, and hence loss of information in the parallelized variant. So how is the information being lost, and what's happening? Can anyone offer some "microsurgery" on methodology for keeping a

Parallel.Foreach() yields no result

自古美人都是妖i 提交于 2019-12-11 14:19:27
问题 I am trying to query a mongo-db parallely using Parallel.Foreach() but I am not getting any results. But when I try to run the same thing in regular foreach loop I am able to perform the expected tasks. var exceptions = new ConcurrentQueue<Exception>(); var secondaryObjectsDictionaryCollection = new Dictionary<string, List<JObject>>(); // This works foreach(var info in infos) { try { name = await commonValidator.ValidateAsync(name); await commonValidator.ValidateIdAsync(name, id); var list =

How to specify the number of parallel tasks executed in Parallel.ForEach? [duplicate]

你说的曾经没有我的故事 提交于 2019-12-11 03:09:32
问题 This question already has answers here : Keep running a specific number of tasks (2 answers) Have a set of Tasks with only X running at a time (5 answers) Closed 5 years ago . I have ~500 tasks, each of them takes ~5 seconds where most of the time is wasted on waiting for the remote resource to reply. I would like to define the number of threads that should be spawned myself (after some testing) and run the tasks on those threads. When one task finishes I would like to spawn another task on

C# Parallel - Adding items to the collection being iterated over, or equivalent?

一笑奈何 提交于 2019-12-10 18:16:59
问题 Right now, I've got a C# program that performs the following steps on a recurring basis: Grab current list of tasks from the database Using Parallel.ForEach(), do work for each task However, some of these tasks are very long-running. This delays the processing of other pending tasks because we only look for new ones at the start of the program. Now, I know that modifying the collection being iterated over isn't possible (right?), but is there some equivalent functionality in the C# Parallel

Foreach -parallel object

痞子三分冷 提交于 2019-12-10 15:48:43
问题 Recently we started working on scripts that take a very long time to complete. So we dug into PowerShell workflows. After reading some documentation I understand the basics. However, I can't seem to find a way to create a [PSCustomObject] for each individual item within a foreach -parallel statement. Some code to explain: Workflow Test-Fruit { foreach -parallel ($I in (0..1)) { # Create a custom hashtable for this specific object $Result = [Ordered]@{ Name = $I Taste = 'Good' Price = 'Cheap'

Task.StartNew() vs Parallel.ForEach : Multiple Web Requests Scenario

一世执手 提交于 2019-12-08 16:54:26
问题 I have read through all the related questions in SO, but a little confused on the best approach for my scenario where multiple web service calls are fired. I have an aggregator service that takes an input, parses and translates it into multiple web requests, makes the web request calls (unrelated, so could be fired in parallel) and consolidates the response which is sent back to the caller. The following code is used right now - list.ForEach((object obj) => { tasks.Add(Task.Factory.StartNew(

Executing N number of threads in parallel and in a sequential manner

非 Y 不嫁゛ 提交于 2019-12-08 16:12:03
问题 I have an application where i have 1000+ small parts of 1 large file. I have to upload maximum of 16 parts at a time. I used Thread parallel library of .Net. I used Parallel.For to divide in multiple parts and assigned 1 method which should be executed for each part and set DegreeOfParallelism to 16. I need to execute 1 method with checksum values which are generated by different part uploads, so i have to set certain mechanism where i have to wait for all parts upload say 1000 to complete.

In parallel call, limit executions per second

两盒软妹~` 提交于 2019-12-07 17:23:14
问题 Using TPL / Parallel.ForEach is there an out-of-the-box way to limit the number of times a method is called per unit of time (i.e. no more than 50 calls per second). This is different than limiting the number of threads. Perhaps there's some simple hack to make this work? 回答1: One solution is to make a thread-safe version of the following https://stackoverflow.com/a/7728872/356790 /// <summary> /// This class limits the number of requests (method calls, events fired, etc.) that can occur in a