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
2008-11-06 06:25:57
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
2008-11-06 08:07:56
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
2008-11-06 08:09:16
That is my SOLO bookmarked reference for threads. Thanks for taking the time to write that down and very pleased to meet you.
Gishu
2008-11-06 08:39:03
@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
2008-11-06 13:09:04