View Full Version : creating threads in C#

07-17-2009, 08:13 PM
Can someone please break down a simple statement for a relative newbie?

Thread firstThread = new Thread (new ThreadStart (Method1));

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

new ThreadStart (Method1)

new Thread (new ThreadStart (Method1))

Thread firstThread = new Thread (new ThreadStart (Method1));

Thanks for any help you can give.

07-17-2009, 08:35 PM
new ThreadStart (Method1)

ThreadStart is a delegate. Method1 is a function that matches the ThreadStart delegate. Method1 is going to be the entry point (aka the starting point) for the new thread.

new Thread (new ThreadStart (Method1))

The thread object is being created.

Thread firstThread = new Thread (new ThreadStart (Method1));

The created thread object is being assigned to firstThread.

Depending on what you are wanting to do with threads, the BackgroundWorker class which I *think* is in the System.ComponentModel namespace makes it easier to have background worker threads separate from your main program flow.

07-18-2009, 03:25 PM
This is a crosspost of http://www.daniweb.com/forums/thread204868.html

07-20-2009, 09:21 PM

>This is a crosspost of http://www.daniweb.com/forums/thread204868.html

Yes, it is. So what?

Posting to forums at different websites is not the same as posting to more than one forum at a single website. The idea behind not cross-posting to multiple forums at a single website is to ensure that posts are directed appropriately. Posting to forums with similar topics at different websites is in no way directing posts inappropriately.

The purpose of posting questions at more than one website is to maximize the chance of getting answers, of course! And why not? Any given question is usually answered at only a minority of forums. But by posting my questions to forums at multiple websites, several different people have responded to each and every one of my questions. They've each been helpful and brought something to the discussion that others at other websites had not thought of. So what does it matter if such helpful people are distributed over several websites?