creating threads in C# - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


creating threads in C#

BobLewistonBobLewiston Posts: 43Member
Can someone please break down a simple statement for a relative newbie?

[CODE]Thread firstThread = new Thread (new ThreadStart (Method1));[/CODE]

In other words, what is happening at each stage here:

[CODE]new ThreadStart (Method1)[/CODE]

[CODE]new Thread (new ThreadStart (Method1))[/CODE]

[CODE]Thread firstThread = new Thread (new ThreadStart (Method1));[/CODE]

Thanks for any help you can give.


  • DataDinkDataDink Posts: 135Member
    Assuming you understand exactly what a thread is:

    "new Thread()" simply creates a new thread in memory

    a thread however without any code to execute is pretty useless and that is all the "ThreadStart" object is. It's just a delegate that you create to pass the thread a method from your code.

    This way your method runs in its own thread - simutaneous to the rest of your code.

    So after all that statement is done there - you just start the thread and whatever method you've passed it will start executing "in the background" as it were.
Sign In or Register to comment.