Multithreaded service, BackgroundWorker vs ThreadPool?

后端 未结 5 1570
暖寄归人
暖寄归人 2020-12-07 19:01

I have a .NET 3.5 Windows Service. I\'m testing with a small application that just sleeps threads after starting them, for random timespans of 300 to 6500ms. I have various

5条回答
  •  暖寄归人
    2020-12-07 19:57

    Definitely not Backgroundworker for a service

    You should go with Tasks in the System.Threading.Tasks namespace, could also use tasks Parallel threading execution

    http://msdn.microsoft.com/en-us/library/dd460717.aspx
    I quote: "Starting with the .NET Framework 4, the TPL is the preferred way to write multithreaded and parallel code."

    Some readings:
    http://msdn.microsoft.com/en-us/library/dd997413%28VS.100%29.aspx

    Start here:
    http://msmvps.com/blogs/brunoboucard/archive/2010/04/09/parallel-programming-task-oriented-parallel-part-1.aspx
    http://msmvps.com/blogs/brunoboucard/archive/2010/05/18/parallel-programming-in-c-4-0-task-oriented-parallel-programming-part-2.aspx
    http://msmvps.com/blogs/brunoboucard/archive/2010/11/06/parallel-programming-with-c-4-0-part-3.aspx

    More examples
    http://www.dotnetcurry.com/ShowArticle.aspx?ID=489
    http://www.dotnetfunda.com/articles/article984-parallel-compting-in-csharp-40-.aspx

提交回复
热议问题