Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-17-2009, 07:13 PM   PM User | #1
BobLewiston
Regular Coder

 
Join Date: Nov 2008
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
BobLewiston is an unknown quantity at this point
creating threads in C#

Can someone please break down a simple statement for a relative newbie?

Code:
Thread firstThread = new Thread (new ThreadStart (Method1));
In other words, what is happening at each stage here:

Code:
new ThreadStart (Method1)
Code:
new Thread (new ThreadStart (Method1))
Code:
Thread firstThread = new Thread (new ThreadStart (Method1));
Thanks for any help you can give.
BobLewiston is offline   Reply With Quote
Old 07-17-2009, 07:35 PM   PM User | #2
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,042
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
Code:
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.

Code:
new Thread (new ThreadStart (Method1))
The thread object is being created.

Code:
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.
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Old 07-18-2009, 02:25 PM   PM User | #3
scottk
New Coder

 
Join Date: Jul 2009
Location: Atlanta, GA
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
scottk is an unknown quantity at this point
This is a crosspost of http://www.daniweb.com/forums/thread204868.html
scottk is offline   Reply With Quote
Old 07-20-2009, 08:21 PM   PM User | #4
BobLewiston
Regular Coder

 
Join Date: Nov 2008
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
BobLewiston is an unknown quantity at this point
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?
BobLewiston is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:13 AM.


Advertisement
Log in to turn off these ads.