using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace Step3
{
class Program
{
delegate void CallRun();
static Thread t1 = null;
static Thread t2 = null;
static void run1()
{
for(int i = 0; i < 1000; i++)
{
Console.WriteLine("run1 : " + i);
}
}
static void run2()
{
for (int i = 0; i < 1000; i++)
{
Console.WriteLine("run2 : " + i);
if (i == 100)
{
//t1.Abort();//스레드 강제종료
t1.Suspend();//스레드 정지
Console.WriteLine("스레드 2초간 정지");
//Thread Sleep - 2 초동안
System.Threading.Thread.Sleep(2000);
t1.Resume();//스레드 다시 시작
}
}
}
static void readNumber()
{
Console.WriteLine("Test Delegate");
Console.WriteLine("델리게이트 스레드 2초간 정지");
//Thread Sleep - 2 초동안
System.Threading.Thread.Sleep(2000);
}
static void Main(string[] args)
{
//스레드 생성시 run에 해당하는 함수 초기화
t1 = new Thread(run1);
t2 = new Thread(run2);
CallRun call = new CallRun(readNumber);
call();
//스레드 시작
t1.Start();
t2.Start();
}
}
}
'Code Archive > C#' 카테고리의 다른 글
| Step2. C# 배열 선언 방법 및 함수 (0) | 2017.03.03 |
|---|---|
| Step1. C# 기초문법 (0) | 2017.03.03 |