Delegates are a few of the objects that make threading easier in .NET reference. They can be used to asynchronously invoke a method. What other objects exist in framework 4.5 (o
Well let's see here:
ThreadPool
class - kinda old, but still reliable for a simple producer-consumer pattern.BackgoundWorker
(.NET 2.0+) - another old-school construct, providing useful features for executing tasks in the background in GUI applications.Timer
s - useful for executing code at specified intervals using a background thread.Task
class (.NET 4.0+) - threading abstractions that run on the underlying thread pool and provide many useful features like exception marshaling and scheduling. Useful for the so-called "task parallelism" pattern.Parallel.For
, Parallel.ForEach
(.NET 4.0+) - good for executing the same operation over a set of data in parallel. Useful for the so-called "data parallelism" pattern.Parallel.Invoke
(.NET 4.0+) - a further abstraction over Task
s. Simply fires off several pieces of code (methods, lambdas) in parallel.