Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 07-17-2009, 02:30 PM   #1 (permalink)
 
Junior Techie

Join Date: Nov 2008

Posts: 79

BobLewiston is on a distinguished road

Default 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  
Old 07-17-2009, 04:44 PM   #2 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default Re: creating threads in C#

Code:
new ThreadStart (Method1)
Creates a delegate of type ThreadStart. When the delegate is invoked (by calling its 'Invoke' method), it will call Method1.

Code:
new Thread (new ThreadStart (Method1))
Creates a new thread. When the thread is executed (by calling its 'Start' method), it will invoke the ThreadStart delegate.

Code:
Thread firstThread = new Thread (new ThreadStart (Method1));
Assigns a reference to the newly created thread to the firstThread variable.

In a nutshell, this code creates a new thread on which to execute Method1.
jaeusm is offline  
 
Closed Thread

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
creating videos (lots of cutting involved) stb1swat Computer Audio & Multimedia 1 10-11-2008 11:15 PM
On the lookout for the perfect Avatar Virtual Assistant creating Software onauc Web Graphics, Design, Digital Images 1 11-20-2007 07:48 AM
(Java) Problem creating and passing an Integer object? Toshiro Programming Discussions 1 10-17-2007 08:00 PM
Cant see my threads Ninja4621 Site Feedback & Suggestions 9 07-29-2007 03:07 PM