c# - Parallel.ForEach not spinning up new threads -


parallel.Froine Not New Threads Spinning Up

Hello All, We have very much IO-intensive operation That we wrote for parallel.Forich for Microsoft's parallel extensions.NET Framework We need to delete a large number of files, and we represent files that are destroyed in the list of lists. Each nested list has 1000 messages, and we have 50 of these lists. The point here is that when I look at the log later, I only look at a thread inside our parallel. FEE block one

The code looks here:

  from the list & lt; From the list & lt; Message & gt; & Gt; ExpiredMessagesList = GetNestedListOfMessages (); Forrest (list & sub-list; message list); {parallel.Forich (sublist, msg = & gt; {try {logger.logEvent (trace eventtip information, "thread {1} Message {Purging}}, msg.MessageID, msg .ExtensionID, Thread.CurrentThread.Name); DeleteMessageFiles (msg);} Hold (Exception Pre) {Logger.LogException (TraceEventType.Error, ex);}});}  

I wrote some sample code with no simple data structure and no Io logic, and I could see many different threads executed in parallel. ForEach Block Or are we doing something wrong parallel.ForEach in the above code? Can it be a list of lists that it is tripping, or is there a limit of some sort of threading for IO operations?

There are some possibilities.

First of all, in most cases, parallel.forike Will not create a new thread, it uses .NET 4 Thunderpool (all TPL), and reuse the Threadpool Threads Will.

That being said, Smanantrkforac uses a Partishning Stratejijh, which is based on the size of the list. My first estimate is that there are several messages in your "External" list, but there is an example of only one message in the internal list, so the ForEach Partitioner is using only one thread, with an element, parallel Just enough to use the main thread, and spin does not work on any background thread.

Generally, in such circumstances, it does not have a parallel external loop, internal loop, it will generally give you better performance (because you will have large working items), although the size of the loop It is difficult to know without the good information and the size of the work unit.

Another possibility:

You can also, possibly, parallel both the inner and outer ends, but without any outline, it would be difficult to say that the best What will be the option.

For your logging, try using [Thread.MenzTrudeID] [1] instead of Thread.ContentTrade.Name. Since parallel uses threads thread, "name" is often the same on many threads. You might think that you are using only one thread when you are actually using more than one ....


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -