Code/C#
[C#] Thread 샘플 코드 4
Hide Code
2007. 12. 8. 12:38
Thread 간에 서로 얼마자 자주 interupt 가 일어나는지를 알 수 있는 샘플 코드이다.
두개의 thread가 화면에 점과 대쉬를 표시한다.
결과 화면을 보면 인터럽트의 정도를 확인할 수 있다.
두개의 thread가 화면에 점과 대쉬를 표시한다.
결과 화면을 보면 인터럽트의 정도를 확인할 수 있다.
using System;
using System.Threading;
namespace ThreadSample
{
class Program
{
public const int Repetitions = 1000;
static void Main(string[] args)
{
ThreadStart myThreadStart = new ThreadStart(DoWork);
Thread myThread = new Thread(myThreadStart);
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('.');
}
}
}
}
using System.Threading;
namespace ThreadSample
{
class Program
{
public const int Repetitions = 1000;
static void Main(string[] args)
{
ThreadStart myThreadStart = new ThreadStart(DoWork);
Thread myThread = new Thread(myThreadStart);
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('.');
}
}
}
}