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

Published 15 March 04 04:02 PM

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]
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Jerry Pisk said on March 15, 2004 8:51 PM:
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.
# Richard Blewett said on March 17, 2004 1:49 AM:
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.
# Tatham Oddie said on March 17, 2004 5:03 AM:
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>.
# Tatham Oddie said on March 17, 2004 5:04 AM:
Lets try again on those URLs... The blog is at:

http://e-oddie.com/blog/professional/archive/2004/03/10/221.aspx

And the download is at:

http://www.e-oddie.com/downloads/professional/Feb04%20NetUG%20Presentation.zip
# abd said on May 9, 2004 4:29 AM:
Where can I find sample C# code for simple threading?
# Jarda said on June 25, 2004 10:18 AM:


Shut this fucking add comments section, too many spam like my post.
# Reviews said on June 27, 2004 11:20 AM:
http://www.favourite-links.com
http://www.links4you.biz
# ok said on July 18, 2004 12:29 AM:
my web:
http://www.sj55.com/pic_sort http://www.zw88.com/paopaotang.htm http://www.zw88.com/sj.htm http://www.zw88.com/sm/
http://www.zw88.com/sms/ http://www.zw88.com/zw.htm http://www.resou.com/8888.htm http://www.sj55.com/pic/pic_1130.htm
# dianying xia zai said on July 26, 2004 12:03 AM:
dianying xia zai:http://www.kamun.com/
movie down:http://movie.kamun.com/
mp3 xia zai:http://music.kamun.com/
engage:http://club.kamun.com/
# RebelGeekz said on December 28, 2004 4:54 AM:
[http://itpeixun.51.net/][http://aissl.51.net/][http://kukuxz003.freewebpage.org/][http://kukuxz001.51.net/][http://kukuxz003.51.net/][http://kukuxz005.51.net/][http://kukuxz002.51.net/][http://kukuxz004.freewebpage.org/][http://kukuxz007.51.net/][http://kukuxz001.freewebpage.org/][http://kukuxz006.51.net/][http://kukuxz002.freewebpage.org/][http://kukuxz004.51.net/][http://kukuxz008.51.net/][http://kukuxz009.51.net/][http://kukuxz005.freewebpage.org/][http://kukuxz006.freewebpage.org/][http://kukuxz007.freewebpage.org/][http://kukuxz009.freewebpage.org/]
# C Frequently Asked Questions Where can I find sample C code for | Insomnia Cure said on June 9, 2009 9:03 PM:

PingBack from http://insomniacuresite.info/story.php?id=10124

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

This Blog

Syndication

Page view tracker