Code/C#

[C#] C# 2.0 스타일 Thread 사용법과 예제

Hide Code 2007. 12. 8. 12:51
C# 2.0 에서는 ThreadStart delegate를 사용하지 않아도 된다.

아래 예제를 보자.

아래 예제는 앞 예제와 같은 것이다.

하지만 ThreadStart delegate를 사용하지 않았다.



using System;
using System.Threading;

namespace ThreadSample
{
   class Program
   {
       public const int Repetitions = 1000;

       static void Main(string[] args)
       {
           Thread myThread = new Thread(DoWork);
           myThread.Start();

           for (int count = 0; count < Repetitions; count++)
           {
               Console.Write('-');
           }

           myThread.Join();
       }

       public static void DoWork()
       {
           for (int count = 0; count < Repetitions; count++)
           {
               Console.Write('.');
           }
       }
   }
}