views:

1130

answers:

1

What is the difference between parameterizedThreadstart, Threadstart and Thread?

+4  A: 

ThreadStart and ParameterizedThreadStart are delegate types, defined like this:

 public delegate void ThreadStart()
 public delegate void ParameterizedThreadStart(object state)

They are both used to specify the action which a new thread will take. Clearly ParamaterizedThreadStart takes a parameter whereas ThreadStart doesn't :) This used to be a very handy way of giving a new thread a task with a specific piece of data - now I just use anonymous functions acting as closures.

The Thread class represents the thread of execution itself - you create one (with one of the above delegates), start it, and then let it run.

See my article on parameterized threading for more details - although from here it seems to be down right now :(

Jon Skeet
Re "this used to be" - ParameterizedThreadStart was introduced in .NET 2.0, along with anonymous methods in C# 2.0 - so I don't think (for C# at least) there has ever been a time when ParameterizedThreadStart was any more useful. I like type-checking, so I always use ThreadStart with a capture.
Marc Gravell
Arguably, this was more useful for VB (am I right in thinking VB didn't/doesn't have anonymous methods? My VB knowledge is... lacking.)
Marc Gravell
That is my SOLO bookmarked reference for threads. Thanks for taking the time to write that down and very pleased to meet you.
Gishu
@Gishu: You too, and thanks for the feedback - but you should also look at Joe Albahari's threading site: http://www.albahari.com/threading/
Jon Skeet