Works just as good without the Threadstart

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
 
A

Arne Vajhøj

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
 
A

Arne Vajhøj

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
 
A

Arne Vajhøj

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top