PPL vs BackgroundWorker


  • I’m using Visual Studio 2010 Professional C++.
    To parallel program in C++, I must use PPL (Parallel Patterns Library), not TPL (Task Parallel Library) which is for C#.  Correct?
    I’ve been using BackgroundWorker and it has accomplished what I needed.
    Is there a reason/benefit to switching over to PPL and rewrite the code to use parallel_for, parallel_invoke, etc.?
    Saturday, March 10, 2012 5:01 AM


All replies

  • Hello,

    Re: PPL and TPL

    PPL is the programming model we are encouraging and supporting for writing parallel code in C++. 

    Re: BackgroundWorker

    Do you mean BackgroundWorker in C#? if your app is primarily a .NET app, and if it meets your needs then I dont see a reason or benefit to switching over to PPL. Some developers do prefer C++ in general for better performance and to avoid garbage collection. So if either of these are a concern, then switching to C++ may be beneficial. 

    Also note that PPL consists of both the structured parallel algorithms (parallel_for, invoke etc) as well as async paradigm (parallel tasks and continuations). More resources: and

    Rahul V. Patil

    Tuesday, March 13, 2012 3:06 AM
  • I’m not using C#.  I’m using C++.
    BackgroundWorker is a feature of Visual Studio 2010 Professional C++.
    I’m using .NET because it allows easy creation of forms & windows.
    Incorporating BackgroundWorker is truly effortless.
    You simply drag & drop BackgroundWorker from Toolbox onto your form and you’re ready to go.
    There’s some info regarding BackgroundWorker vs TPL.
    However, there’s nothing regarding BackgroundWorker vs PPL.
    My question is, if you’re already using BackgroundWoker in your C++, is there a benefit to switching over to PPL.
    Some have claimed that if you’re using BackgroundWorker in C#, then TPL is the logical step above.
    What about PPL vs BackgroundWorker?
    Tuesday, March 13, 2012 3:46 AM
  • Hello,

    I assume

    a) you mean BackgroundWorker class in .NET.

    b) You are using C++ CLI  (and not pure C++) to work with this.

    If so, then PPL does not work with C++ CLI. However, you could use TPL in C++ CLI.

    PS: If you mean some other BackgroundWorker class, please let me know.

    Rahul V. Patil

    Tuesday, March 13, 2012 10:47 PM
  • Yes, I’m using that BackgroundWorker class.
    I’m using C++/CLI, not pure C++.
    I mistakenly thought that TPL is for C#, and PPL is for C++.
    I didn’t know that I can use TPL in C++/CLI.
    I’ll investigate further and look into using TPL in C++/CLI.
    Thank you.
    Wednesday, March 14, 2012 3:10 AM
  • Thought I'd jump in and help answer the original question, since it's an important one.  For me, the BackgroundWorker class is perfect when you want to do something in the background and not freeze-up the UI waiting for that to finish.  For example: you need to access a network resource (file, web server) or make a call into the cloud.  You don't want to do that from a button click and freeze the UI, so you instantiate a BackgroundWorker and let it make the call for you.  And the event-based nature of the BackgroundWorker makes it easy to (a) integrate progress and final result display in the UI, and (b) avoid the "cross-thread UI update exception" that happens when a background thread tries to touch the UI.

    So BackgroundWorker does this one thing really well, but that's about it.  TPL is a much more general mechanism for asynchronous and parallel programming.  For example, the new async and await keywords (which hide the TPL) can be used instead of the BackgroundWorker class; you use async and await right there in the original UI button click code, and get asynchronous call and proper return handling almost for free.  And then the TPL offers a ton of functionality around parallel program for increasing the performance of your program:  tasks, work-stealing, high-level parallel for and foreach, etc. 

    So I would recommend learning about the TPL so you'll be ready when you need to do things that BackgroundWorker was not designed to do.


      - joe

    Wednesday, March 14, 2012 7:13 AM