parallel.foreach

using Parallel.ForEach with/or async/await

雨燕双飞 提交于 2019-12-07 16:42:43
问题 I try to verify my image URLs to see whether or not they are valid. I have so many of them that it take hours to complete this task. Therefore, I decided to do it asynchronously. I would like to know if there are any big differences or advantage of doing my code as below. My main functions are: Async Function testUrl_async(ByVal myImageurl As String) As Task(Of Boolean) myHttpResponse = Await myHttpClient.GetAsync(myImageurl) If myHttpResponse.IsSuccessStatusCode Then mySuccess = True Else

Howto: Parallel.Foreach executes many processes, after each process run a new process (but one at a time)? [closed]

China☆狼群 提交于 2019-12-07 13:46:21
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I'm sure someone knows this and I will be very thankful for the answer. I don't know much about delegates and asynch and the like - so please give me a general example of how I could implement. I have a workflow

Async await and parallel

陌路散爱 提交于 2019-12-07 02:07:31
问题 I'm bit confused on how async/await can work as parallel so i made a test code here: i try to send 6 task i simulated with a list. each of this task will execute 3 other subtask. you can copy/paste for test using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { //job simulation Func<int, string, Tuple<int, string>> tc = Tuple

Threading and SqlFileStream. The process cannot access the file specified because it has been opened in another transaction

北战南征 提交于 2019-12-06 19:29:46
问题 I am extracting content of the Files in SQL File Table. The following code works if I do not use Parallel. I am getting the following exception, when reading sql file stream simultaneously (Parallel). The process cannot access the file specified because it has been opened in another transaction. TL;DR: When reading a file from FileTable (using GET_FILESTREAM_TRANSACTION_CONTEXT) in a Parallel.ForEach I get the above exception. Sample Code for you to try out: https://gist.github.com/NerdPad

In parallel call, limit executions per second

雨燕双飞 提交于 2019-12-06 03:34:51
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? SFun28 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 given unit of time. /// </summary> class RequestLimiter { #region Constructors /// <summary> ///

using Parallel.ForEach with/or async/await

こ雲淡風輕ζ 提交于 2019-12-05 20:50:43
I try to verify my image URLs to see whether or not they are valid. I have so many of them that it take hours to complete this task. Therefore, I decided to do it asynchronously. I would like to know if there are any big differences or advantage of doing my code as below. My main functions are: Async Function testUrl_async(ByVal myImageurl As String) As Task(Of Boolean) myHttpResponse = Await myHttpClient.GetAsync(myImageurl) If myHttpResponse.IsSuccessStatusCode Then mySuccess = True Else mySuccess = False End If Return mySuccess End Function Function testUrl(ByVal myImageurl As String) As

What is the performance differences between using parallel.foreach and task inside foreach loop?

蹲街弑〆低调 提交于 2019-12-05 12:05:01
I would like to know what is the best way or are there any documents/articles that can help me to identify what is the differences of using Parallel.foreach and Task within a normal for each loop, like the following: case 1 - Parallel.foreach: Parallel.foreach { // Do SOmething thread safe: parsing an xml and then save // into a DB Server thry respoitory approach } case 2 - Task within foreach: foreach { Task t1 = Task.factory.startNew(()=> { //Do the same thing as case 1 that is thread safe } } Task.waitall() I did do my own tests and the result show case 1 perform way better than case 2. The

Parallelizing IO Bound (Network) ForEach Loop

懵懂的女人 提交于 2019-12-05 11:52:33
I have a few different ways of upload entire directories to Amazon S3 within my application depending on what options are selected. Currently one of the options will perform an upload of multiple directories in parallel. I'm not sure if this is a good idea as in some cases it sped up the upload and other cases it slowed it down. The speed up appears to be when there are a bunch of small directories, but it slows down if there are large directories in the batch. I'm using the parallel ForEach loop seen below and utilizing the AWS API's TransferUtility.UploadDirectoryAsync() method as such:

Async await and parallel

笑着哭i 提交于 2019-12-05 08:13:15
I'm bit confused on how async/await can work as parallel so i made a test code here: i try to send 6 task i simulated with a list. each of this task will execute 3 other subtask. you can copy/paste for test using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { //job simulation Func<int, string, Tuple<int, string>> tc = Tuple.Create; var input = new List<Tuple<int, string>>{ tc( 6000, "task 1" ), tc( 5000, "task 2" ), tc( 1000,

Threading and SqlFileStream. The process cannot access the file specified because it has been opened in another transaction

半世苍凉 提交于 2019-12-04 23:28:01
I am extracting content of the Files in SQL File Table. The following code works if I do not use Parallel. I am getting the following exception, when reading sql file stream simultaneously (Parallel). The process cannot access the file specified because it has been opened in another transaction. TL;DR: When reading a file from FileTable (using GET_FILESTREAM_TRANSACTION_CONTEXT) in a Parallel.ForEach I get the above exception. Sample Code for you to try out: https://gist.github.com/NerdPad/6d9b399f2f5f5e5c6519 Longer Version: Fetch Attachments, and extract content: var documents = new List