GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 17-Jul-2009, 13:24
BobLewiston BobLewiston is offline
Junior Member
 
Join Date: Nov 2008
Posts: 46
BobLewiston is on a distinguished road

Creating threads in C#


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

C-SHARP / C# Code:
Thread firstThread = new Thread (new ThreadStart (Method1));

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

C-SHARP / C# Code:
new ThreadStart (Method1)

C-SHARP / C# Code:
new Thread (new ThreadStart (Method1))

C-SHARP / C# Code:
Thread firstThread = new Thread (new ThreadStart (Method1));

Thanks for any help you can give.
Last edited by admin : 21-Jul-2009 at 21:13. Reason: Please insert your example C# codes between [CSHARP] and [/CSHARP] tags
  #2  
Old 21-Jul-2009, 09:43
tempnode tempnode is offline
New Member
 
Join Date: Jul 2009
Posts: 3
tempnode is on a distinguished road

Re: Creating threads in C#


Sure, I can help =)


C-SHARP / C# Code:
Thread firstThread = new Thread (new ThreadStart (Method1));

You are creating a thread called firstThread and creating a delegate called Method1(). The ThreadStart instantiation (new ThreadStart(Method1)) is simply saying that when you start executing firstThread, it will jump down to Method1() in your code and start processing what's in that function.


This delegate method (here, called Method1()) will be associated with firstThread.... so, when you call firstThread.Start(), the functionality in Method1() will be performed. Now, you must still define and code the Method1() method yourself. I *believe* that it must return a void and take 0 parameters in the parameter list.

So here is what your code could look like:

C-SHARP / C# Code:
public void ProcessStuff()
{
    Thread myThread = new Thread(new ThreadStart(PerformThreadDuties));
    myThread.Start();
}

private void PerformThreadDuties()
{
    // do thread work here
}
Last edited by admin : 21-Jul-2009 at 21:12. Reason: Please insert your example C# codes between [CSHARP] and [/CSHARP] tags
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error compiling Apache 2.2.10 tiagofgarcia Apache Web Server Forum 2 10-Nov-2009 14:31
SIGTERM to main process does not kill detached threads!! :( deepti_v C++ Forum 0 31-Jul-2008 05:31
Thread synchronization Assignment help!! rossi143 C Programming Language 1 25-Mar-2007 21:10
user level threads in C beuh Miscellaneous Programming Forum 2 17-Oct-2006 06:44
Apache2 config issues monev Apache Web Server Forum 2 28-Jun-2004 07:19

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:25.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.