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!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.