C# Frequently Asked Questions

The C# team posts answers to common questions

Where can I find sample C# code for simple threading?

Refer to the System.Threading namespace on MSDN for full details. Meanwhile here is a quick taste.

using System; 
using System.Threading; 

class ThreadTest 
{ 
    public void Runme() 
    { 
        Console.WriteLine("Runme Called"); 
        Thread.Sleep(10000); 
    }

    public static void Main(String[] args)
    { 
        ThreadTest b = new ThreadTest(); 
        Thread t = new Thread(new ThreadStart(b.Runme)); 
        t.Start(); 

        Console.WriteLine("Thread 't' started.");
Console.WriteLine("
There is no telling when " +
"'Runme' will be invoked. "); t.Join(); Console.WriteLine("Thread 't' has ended."); } }
[Author: Santosh Zachariah]
Published Monday, March 15, 2004 4:02 PM by CSharpFAQ
Filed under:

Comments

 

Jerry Pisk said:

Given the code above "Rumme Called" can actually execute before "Thread 't' started. There is no telling when 'Runme' will be invoked." I'm sure there are going to be a lot of beginners wondering what happened.
March 15, 2004 8:51 PM
 

Richard Blewett said:

Maybe the answer shold have been "because there is no such thing as simple threading". Every example of real world usage carries with it a massive amount of extra complexity. In many ways, giving simple examples gives the impression that threading can be simple - and in my experience that simply isn't true.
March 17, 2004 1:49 AM
 

Tatham Oddie said:

I did a presentation on this a few weeks ago which most people seemed to understand. It covers several models for mutlithreaded programming.

The blog post it at <http://e-oddie.com/blog/professional/archive/2004/03/10/221.aspx>.

The powerpoint and code can be downloaded from <http://www.e-oddie.com/downloads/professional/Feb04%20NetUG%20Presentation.zip>.
March 17, 2004 5:03 AM
 

Tatham Oddie said:

March 17, 2004 5:04 AM
 

abd said:

Where can I find sample C# code for simple threading?
May 9, 2004 4:29 AM
 

Jarda said:



Shut this fucking add comments section, too many spam like my post.
June 25, 2004 10:18 AM
 

Reviews said:

June 27, 2004 11:20 AM
 

ok said:

July 18, 2004 12:29 AM
 

dianying xia zai said:

July 26, 2004 12:03 AM
 

RebelGeekz said:

December 28, 2004 4:54 AM
 

C Frequently Asked Questions Where can I find sample C code for | Insomnia Cure said:

June 9, 2009 9:03 PM
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker