parallel-extensions

Passing values with Parallel Extensions and VB.net

I am looking for an example of how to do the following in VB.net with Parallel Extensions. Dim T As Thread = New Thread(AddressOf functiontodowork) T1.Start(InputValueforWork) Where I'm getting stuck is on how to pass into the task my parameter InputValueforWork Dim T As Tasks.Task = Tasks.Task.Create(AddressOf functiontodowork) An...

Why is LazyInit<T> restricted to reference types

I have a pseudo-realtime data processing application where I would like to use LazyInit<double> so I don't do calculations I don't need, but LazyInit<T> restricts T to classes. I can work around it, but I'd obviously prefer not to. Does anybody know why this is? ...

Parallel Extensions: Help Me Understand LazyInit<T>

Update for future readers: When .NET 4 comes out, LazyInit<T> from the CTP will have been renamed to Lazy<T> and will be changed from a struct to a class, so very little of this will apply, except as an illustration of why mutable structs can be problematic if you're not careful. I've been experimenting with LazyInit in the Parallel Ext...

Can I develop production code with Microsoft Parallel Extensions to .NET Framework 3.5, June 2008 Community Technology Preview?

Is there any recommendation against using this CTP? Is it unstable? ...

Parallel Extensions Equivalent in Java

I have some experience using parallel extensions in .Net development, but I was looking at doing some work in Java that would benefit from an easy to use parallelism library. Does the JVM offer any comparable tools to parallel-extensions? ...

How can I prevent AppDomainUnloadedException after NUnit tests PLINQ code?

How can I diagnose and minimize or prevent AppDomainUnloadedException? NUnit 2.5.2 consistently throws AppDomainUnloadedException after long (>10s) tests involving PLINQ. Back in July 2008, Stephen Toub said: Yes, the scheduler in the CTP doesn't handle thread aborts very well, which frequently causes the process to crash when...

Using a hashtable inside a Parallel.ForEach??

I have a Parallel.ForEach loop running an intensive operation inside the body. The operation can use a Hashtable to store the values, and can be reused for other consecutive loop items. I add to the Hashtable after the intensive operation is complete, the next loop item can look up in the Hashtable and reuse the object, instead of runni...

How to make PLINQ to spawn more concurrent threads in .NET 4.0 beta 2?

In former versions of Parallel Extensions you could set the number of threads: enumerable.AsParallel(numberOfThreads) But now that overload is not available anymore. How to do it now? ...

Why is the TaskFactory.StartNew method not generic?

The idomatic way to start a new side-effect-only task (that is: a task that returns no result) using the TPL in .NET 4.0 is using the following API: Task Task.Factory.StartNew(Action<object>, object) But why doesn't the signature of this API look like this Task Task.Factory.StartNew<T>(Action<T>, T) or like this Task Task.Factor...

Parallel.ForEach Not Spinning Up New Threads

Parallel.ForEach Not Spinning Up New Threads Hello all, we have a very IO-intensive operation that we wrote using Parallel.ForEach from Microsoft's Parallel Extensions for the .NET Framework. We need to delete a large number of files, and we represent the files to be deleted as a list of lists. Each nested list has 1000 messages in it...

Can I configure the number of threads used by Parallel Extensions?

I'm currently using the Paralle Extensions that are part of Reactive Extensions for .Net(Rx). I believe they are also available through .Net 4 beta releases. 1) Is there any way to determine how many threads are actualyl being utilized. I assume this is related to Environment.ProcessorCount (# of logical cores) but I want to check this....

Parallel Sort Algorithm

I'm looking for a simple implementation of a parallelized (multi-threaded) sort algorithm in C# that can operate on List<T> or Arrays, and possibly using Parallel Extensions but that part isn't strictly necessary. Edit: Frank Krueger provides a good answer, however I wish to convert that example to one that doesn't use LINQ. Also note t...

How can I get parallel extensions to run a function that has two input parameters?

I've tried really hard to get this to work and have had no luck. How can I get parallel extensions to run a function that has two input parameters? I'm using the more recent version, the Reactive Extensions with the 3.5 framework. I need to get the extensions to run act (or the function ProcessOrder) but no matter what I try I can't g...

What is the purpose of BlockingCollection(Of T)

Hi, I´m trying to understand the purpose of BlockingCollection in the context of the new Parallel Stacks on .NET 4. The msdn documentation says: Blockquote BlockingCollection is used as a wrapper for an IProducerConsumerCollection instance, allowing removal attempts from the collection to block until data is available to be remo...

Parallel.Foreach spawning way too many threads

The problem Although the code about which I will talk here I wrote in F#, it is based on the .NET 4 framework, not specifically depending on any particularity of F# (at least it seems so!). I have some pieces of data on my disk that I should update from the network, saving the latest version to the disk: type MyData = { field1 : i...

Multi-threading access to SubmitChanges() (LINQ to SQL)

I am using Visual Studio 2010 Beta 2. In Parallel.For loop I execute the same method with different parameter values. After execution processed data must be stored in the database. But I've got an exception hat says that I could not work with the same data context from different threads. So the question will be how to work with dat...

Reactive Framework vs PLINQ vs Task Parallel Library vs Parallel Extensions

In a few words, can anyone set the record straight what is what? Does this all end up in .NET 4.0 ? ...

Filtering IEnumerable Pattern

Consider the followign simple code pattern: foreach(Item item in itemList) { if(item.Foo) { DoStuff(item); } } If I want to parallelize it using Parallel Extensions(PE) I might simply replace the for loop construct as follows: Parallel.ForEach(itemList, delegate(Item item) { if(item.Foo) { DoStuff(item); ...

Why is ParallelQuery<T>.Where not working when converting to Observable ?

Hi folks, I have an observable collection that I want to process in parallel, then observe the processed values while filtering and finally subscribe a handler that receives the filtered values. My sample is syntactically correct and compiles just fine, and when I run the code, the Where statement doing the filtering is evaluated. Bu...

How to Force an Exception from a Task to be Observed in a Continuation Task?

I have a task to perform an HttpWebRequest using Task<WebResponse>.Factory.FromAsync(req.BeginGetRespone, req.EndGetResponse) which can obviously fail with a WebException. To the caller I want to return a Task<HttpResult> where HttpResult is a helper type to encapsulate the response (or not). In this case a 4xx or 5xx response is not...