To get things started…

To get things started I thought I’d post some information I promised a friend¬†on easy multi-threading techniques in C#/.Net.

First trick is to use the Parrallel Class. This is a new addition in .Net 4.0 that provides version of for and foreach that will automatically split up the loop to run across multiple threads, depending on how many cores the System CPU has and how much load each core is under (this can be controlled too, if need be).

The other is Background Workers. Background workers are best used for slow jobs that might cause the UI to lock up (such as long file IO operations). A Background worker runs whatever task you give it on a separate thread, preventing the UI from locking up and allowing the user to do other thing while they wait for it to complete. The background worker provides a series of events for monitoring its progress.

Hope you find these useful in your future .Net projects.