I found this example of some C# thread code at
http://codeguru.earthweb.com/bbs/wt/wwwthreads.pl?action=list&Board=CSharp
Still leaves a lot of questions open. For example, does the WaitOne
call to a ManualResetEvent release locks? If so, which locks?
Bill
//Module :ThreadDemo.cs
//Author :Richard L. Weeks
// RichardW@stingray.com
//
namespace ThreadDemo {
using System;
using System.Threading;
public class ThreadDemo {
private string m_ThreadMsg;
private ManualResetEvent m_StopEvent;
public ThreadDemo( ManualResetEvent StopEvent, string Msg ) {
m_StopEvent = StopEvent;
m_ThreadMsg = Msg;
}
//The Thread Proc
public void Run( ) {
TimeSpan waitTime = new TimeSpan(0,0,5);
do {
Console.WriteLine( m_ThreadMsg );
} while( !m_StopEvent.WaitOne(waitTime, false) );
}
}
public class ThreadDemoEntry {
public static void Main( ) {
ManualResetEvent StopEvent = new ManualResetEvent(false);
ThreadDemo td = new ThreadDemo( StopEvent, "Hello From Thread" );
Thread T = new Thread( new ThreadStart( td.Run ) );
Console.WriteLine( "Press Enter to Start Thread. Press
Enter again to Exit" );
Console.ReadLine( );
T.Start( );
Console.ReadLine( );
StopEvent.Set( );
T.Join( );
Console.WriteLine("Have a nice day");
}
}
}
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:27 EDT