Works just as good without the Threadstart

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

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
 
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
 
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
 
Arne said:
[...]
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
 
Back
Top