Even when telling each of these threads to sleep for 100 million milliseconds, it still executes immediately. Why doesn't Sleep slow it down?
using System;using System.Collections.Generic;using System.Text;using System.Threading;namespace TestThreads{class Program {static void Main(string[] args) { ThreadStart operation =new ThreadStart(SimpleWork); Thread theThread =new Thread(operation); theThread.Start(); }static void SimpleWork() { Console.WriteLine("Thread: {0}", Thread.CurrentThread.ManagedThreadId); } }}This works for me:
static void Main( string[] args )
{
ThreadStart operation = new ThreadStart( SimpleWork );
Thread theThread = new Thread( operation );
theThread.Start();
}
static void SimpleWork()
{
Thread.Sleep( 1000 ); // 1 second
Console.WriteLine( "Thread: {0}", Thread.CurrentThread.ManagedThreadId );
}
0 comments:
Post a Comment