Tuesday, August 16, 2011

Sample Multi-threading in ASP.NET C# console applicatoin

Do download a zip file project at my google code page.

Some notes about starting up threads:
  • Use QueueUserWorkItem to create a thread in a pool.  This has the added benefit of the .NET framework doing some checking for you to see if the CPU is able to handle more work.  If it isn't too busy, it will fire up a thread for you.  It has more overhead than ThreadStart, but is scalable.
  • Use System.ComponentModel.BackgroundWorker for cross-thread communication.  The benefits include:
    • Progress report
    • Cancellation pending property so  you can exit gracefuly.