...

View Full Version : creating threads in C#



BobLewiston
07-17-2009, 07: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.

oracleguy
07-17-2009, 07: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.

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

BobLewiston
07-20-2009, 08:21 PM
scottk:

>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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum