Been playing around with the new version of Pfx for .NET. I must say Ive been very impressed with the improvements since the last CTP for .NET 3.5. So here goes a series of blogs and screen casts on some on various bits of Pfx for .NET 4 BETA 1.
The one thing that really shouts is that the original Pfx types are no longer something for just fine grained parallelism its is a unification of the various threading API’s. Unifying Api’s is something not new to the .NET framework its been happening since 1.1. As developers its great that whilst the framework is evolving a constant effort is being made to refactor and simplify previous complexity.
So previously If I wanted to create a short running piece of background work I would favour the thread pool, if I was to write a long running piece of background activity I would have to create my own custom thread. Creating a short running thread using the thread pool meant either QueueUserWorkItem or Delegate.BeginInvoke, and a long running via new Thread(), and calling Start.
Now for either types of situation you simply create a new Task using the new Task type, either via the Task Factory ( not a real GOF Factory, but don’t get me started on that ), or via new Task()
Task bgTask = Task.Factory.StartNew( MyShortRunningTask);
For a long running task we use the same API but this time giving it a hint that this is a long running task and shouldn’t therefore use a thread pool thread, but create a new thread outside the thread pool
Task bgTask = Task.Factory.StartNew( MyLongRunningTask, TaskCreationOptions.LongRunning);
So too very similar calls but leaving it up to the framework to decide how best to schedule the work.
No comments:
Post a Comment