Task Parallel Library 1 of n

I have just started work on what will be a 6 part series of articles on an in depth look into using the .NET 4 Task Parallel Library (TPL).

I have just published the 1st part in this series of article which is available using this link:

http://www.codeproject.com/KB/cs/TPL1.aspx

  • This article covers the following topics:
  • Comparing Threads and Tasks
  • Starting Tasks
  • Handling Exceptions With Tasks
  • Cancelling Tasks
  • UI Synchronization Using Tasks

I hope it has something there for you, and i hope you read the rest of the articles when I get them up.

Advertisements

6 thoughts on “Task Parallel Library 1 of n

  1. Barry says:

    I don’t see it in your list, but you might be interested in this, covering custom schedulers:

    http://msdn.microsoft.com/en-us/library/ee789351.aspx

    and the full set that are in here (http://go.microsoft.com/fwlink/?LinkID=165717).

    Also the scoping of variables that goes into lambda/anonymous expressions inside Tasks is worth clarifying (see Remarks) – http://msdn.microsoft.com/en-us/library/0yw3tz5k(v=VS.100).aspx

    • sacha says:

      Barry thanks for these links. I was already going to cover custom schedulers, but was not going to write about scoping, so thats a good one, thanks for you links.

  2. sacha says:

    Barry,

    You are talking about standard closures right?

  3. Barry says:

    I had the specific case where I used the limited-concurrency scheduler (for long copying tasks, so I don’t thrash the local disk or flood the network), and wanted to queue up tasks synchronously. Pretend Task.Factory can only run one task at a time (e.g. single core PC):

    void foo()
    {
    Widget w1 = new Widget(arg1, arg2)
    Widget w2 = new Widget(arg3, arg4)

    Task.Factory.StartNew( () => {
    w1.Run(); // stays in scope, as per MS webpage in other comment
    });

    // don’t run until w1 has finished.
    Task.Factory.StartNew( () => {
    w2.Run(); // stays in scope, as per MS webpage in other comment
    });

    } // w1 and w2 now out of scope, and w2 might not have started yet.

    Running w2 worried me for a little while (ex-C++ programmer), until I dug up the MS link in previous comment.

  4. Barry says:

    I should probably add that whilst I could create the objects within the lambda expression, which would partially solve the scoping problem, the arguments might still be scoped locally to foo(), which is still the same scoping issue. Either way, for a someone who is a bit new to C# still, it was a little confusing until I found the right webpage. It just might be worth clarifying it for other people when they read the article. 🙂

  5. sacha says:

    Thanks for the comments Barry, I will do what I can to talk about these issues

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: