Thread에 관한 3번째 샘플 코드이다.
이 샘플 코드는 Thread를 3개 실행 시키는 것이다.
이 샘플 코드는 Thread를 3개 실행 시키는 것이다.
using System;
using System.Threading;
public class NameUsingThread
{
private int time;
private Thread thread;
public NameUsingThread(String n, int t)
{
time = t;
thread = new Thread(new ThreadStart(Run));
thread.Name = n;
thread.Start();
}
public void Run()
{
for (int i = 1; i <= 5; i++)
{
Console.WriteLine(thread.Name + " " + i);
Thread.Sleep(time);
}
}
public static void Main()
{
NameUsingThread bonnie = new NameUsingThread("Bonnie", 500);
NameUsingThread clyde = new NameUsingThread("Clyde", 1000);
Thread.CurrentThread.Name = "Main";
for (int i = 1; i <= 5; i++)
{
Console.WriteLine(Thread.CurrentThread.Name + " " + i);
Thread.Sleep(1500);
}
}
}
using System.Threading;
public class NameUsingThread
{
private int time;
private Thread thread;
public NameUsingThread(String n, int t)
{
time = t;
thread = new Thread(new ThreadStart(Run));
thread.Name = n;
thread.Start();
}
public void Run()
{
for (int i = 1; i <= 5; i++)
{
Console.WriteLine(thread.Name + " " + i);
Thread.Sleep(time);
}
}
public static void Main()
{
NameUsingThread bonnie = new NameUsingThread("Bonnie", 500);
NameUsingThread clyde = new NameUsingThread("Clyde", 1000);
Thread.CurrentThread.Name = "Main";
for (int i = 1; i <= 5; i++)
{
Console.WriteLine(Thread.CurrentThread.Name + " " + i);
Thread.Sleep(1500);
}
}
}
'Code > C#' 카테고리의 다른 글
| [C#] Thread 샘플 코드 4 (0) | 2007.12.08 |
|---|---|
| [C#] Thread & FileStream 사용 예제 (0) | 2007.12.07 |
| [C#] Thread 샘플 코드 2 (0) | 2007.12.07 |
| [C#] Thread 샘플 코드 1 (0) | 2007.12.07 |
| [C#] Extension Methods 샘플 코드 (0) | 2007.12.02 |