task-parallel-library

Is there a Threadsafe Observable collection in .NET 4 ?

Hi, Platform: WPF, .NET 4.0, C# 4.0 Problem: In the Mainwindow.xaml i have a ListBox bound to a Customer collection which is currently an ObservableCollection< Customer >. ObservableCollection<Customer> c = new ObservableCollection<Customer>(); This collection can be updated via multiple sources, like FileSystem, WebService etc. To ...

Parallel.For synchronization with null objects

I am using System.Threading.Tasks.Parallel.For to do some heavyweight processing. My code is: int count = 10; List<MyObj> results = new List<MyObj>(); Parallel.For(0, count, (index) => { MyObj obj = GetMyObjMaybe(); if (obj != null) results.Add(obj); }); if (results.Contains(null)) { //break here, and it does } //som...

Using Parallelization for relatively large loops

I have an 8-core CPU machine with 8 GB memory. Logically the following code can be done in parrallel, but since the loop exposes more than enough opportunities for parallelism since I have far fewer cores available than the size of the loop. Second, every delegate expression allocates some memory to hold the free variables. Is it recomme...

Parallel: how to synchronize properly

I have a following fairly simple scenario: Some data needs to be written into a DB (pretty big collection) that can be partitioned. But I have two problems: Easy one: would like to have an option to print the progress bar, so that would like to know how many records have been inserted so far from time to time (kinda shared counter amon...

Task Parallel Library - How do you get a Continuation with TaskContinuationOptions.OnlyOnCanceled to Fire?

I'm experimenting with the Task support in .NET 4.0 - specifically with the continuation support. What I'm perplexed about is that I can't figure out how to get a continuation with the TaskContinuationOptions.OnlyOnCanceled flag set to execute. If I do a ThrowIfCancellationRequested in my worker routine, it only seems to propagate out ...

In Task Parallel Library: How to defer Task.TaskFactory.FromAsync task execution?

I have a method that returns a task like: public static Task<int> SendAsync(this Socket socket, byte[] buffer, int offset, int count) { if (socket == null) throw new ArgumentNullException("socket"); if (buffer == null) throw new ArgumentNullException("buffer"); return Task.Factory.FromAsync<int>( socket.BeginSend(bu...