List thread safety

No! It is not safe at all, because processed.Add is not. You can do following: items.AsParallel().Select(item => SomeProcessingFunc(item)).ToList(); Keep in mind that Parallel.ForEach was created mostly for imperative operations for each element of sequence. What you do is map: project each value of sequence. That is what Select was created for. AsParallel scales it across … Read more

Can I remove items from a ConcurrentDictionary from within an enumeration loop of that dictionary?

It’s strange to me that you’ve now received two answers that seem to confirm you can’t do this. I just tested it myself and it worked fine without throwing any exception. Below is the code I used to test the behavior, followed by an excerpt of the output (around when I pressed ‘C’ to clear … Read more

Save time with parallel FOR loop

Parallel.For() can improve performance a lot by parallelizing your code, but it also has overhead (synchronization between threads, invoking the delegate on each iteration). And since in your code, each iteration is very short (basically, just a few CPU instructions), this overhead can become prominent. Because of this, I thought using Parallel.For() is not the … Read more

How do Reactive Framework, PLINQ, TPL and Parallel Extensions relate to each other?

PLINQ (Parallel Linq) is simply a new way to write regular Linq queries so that they run in parallel – in other words, the Framework will automatically take care of running your query across multiple threads so that they finish faster (i.e. using multiple CPU cores). For example, let’s say that you have a bunch … Read more

Should i use ThreadPools or Task Parallel Library for IO-bound operations

So i instead decided to write tests for this and see it on practical data. Test Legend Itr: Iteration Seq: Sequential Approach. PrlEx: Parallel Extensions – Parallel.ForEach TPL: Task Parallel Library TPool: ThreadPool Test Results Single-Core CPU [Win7-32] — runs under VMWare — Test Environment: 1 physical cpus, 1 cores, 1 logical cpus. Will be … Read more

Parallel.ForEach vs Task.Factory.StartNew

The first is a much better option. Parallel.ForEach, internally, uses a Partitioner<T> to distribute your collection into work items. It will not do one task per item, but rather batch this to lower the overhead involved. The second option will schedule a single Task per item in your collection. While the results will be (nearly) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)