Prev: the Clear method for the Queue class
Next: WPF - How can I selectively set the “Border brush” of a customcont
From: Tony Johansson on 30 Jun 2010 19:55 Hello! Here I have a simple example to start a Thread. I have noticed that I can skip the Threadstart and pass the working method directly to the Thread C-tor. So what is the point to use ThreadStart when it works just as good without it. public static void MyMethod() { Console.WriteLine("Testing thread"); } static void Main(string[] args) { Thread myThread = new Thread (MyMethod); myThread.Start(); } //Tony
From: Arne Vajhøj on 30 Jun 2010 20:14 On 30-06-2010 19:55, Tony Johansson wrote: > Here I have a simple example to start a Thread. I have noticed that I can > skip the Threadstart and pass the working method directly to the Thread > C-tor. > So what is the point to use ThreadStart when it works just as good without > it. > > public static void MyMethod() > { > Console.WriteLine("Testing thread"); > } > > > static void Main(string[] args) > { > Thread myThread = new Thread (MyMethod); > myThread.Start(); > } For this code: there is no point. But note that it was required in older versions of ..NET, so a lot of programmers learned to use it that way. Arne
From: Arne Vajhøj on 30 Jun 2010 20:17 On 30-06-2010 20:14, Arne Vajh�j wrote: > On 30-06-2010 19:55, Tony Johansson wrote: >> Here I have a simple example to start a Thread. I have noticed that I can >> skip the Threadstart and pass the working method directly to the Thread >> C-tor. >> So what is the point to use ThreadStart when it works just as good >> without >> it. >> >> public static void MyMethod() >> { >> Console.WriteLine("Testing thread"); >> } >> >> >> static void Main(string[] args) >> { >> Thread myThread = new Thread (MyMethod); >> myThread.Start(); >> } > > For this code: there is no point. > > But note that it was required in older versions of > .NET, so a lot of programmers learned to use it > that way. Some testing indicates that: older = 1.x Arne
From: Peter Duniho on 30 Jun 2010 22:16 Arne Vajh�j wrote: > [...] >> But note that it was required in older versions of >> .NET, so a lot of programmers learned to use it >> that way. > > Some testing indicates that: > > older = 1.x Correct. Type inference for delegates didn't show up until C# 2.0. Note that it's not the .NET version that matters, it's the language version. There are some places where more explicit delegate instantiation is required. In particular, situations like the Control.Invoke() method where the type is simply "Delegate", which doesn't provide the compiler enough to go on. You either need to cast the method group name in that situation, or use the pre-C# 2.0 syntax where the delegate constructor is explicitly used. Pete
From: Arne Vajhøj on 30 Jun 2010 22:45
On 30-06-2010 22:16, Peter Duniho wrote: > Arne Vajh�j wrote: >> [...] >>> But note that it was required in older versions of >>> .NET, so a lot of programmers learned to use it >>> that way. >> >> Some testing indicates that: >> >> older = 1.x > > Correct. Type inference for delegates didn't show up until C# 2.0. Note > that it's not the .NET version that matters, it's the language version. So it is the compiler that just adds some glue and not an API change. The practical difference is not so big - C# 2.0 targeting framework 1.1 sounds as a nostarter. Arne |