쓰레드를 생성하기 위해 함수를 생성했습니다 -
public void myThread() {
for (int i = 0; i < 3; i++) {
Console.WriteLine("My Thread");
}
} 위의 함수는 스레드를 생성하기 위해 호출되고 새로운 ThreadStart 대리자가 생성됩니다 -
Demo d = new Demo(); Thread thread = new Thread(new ThreadStart(d.myThread));
예시
다음 코드를 사용하여 간단한 스레드를 만듭니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
class Demo {
public void myThread() {
for (int i = 0; i < 3; i++) {
Console.WriteLine("My Thread");
}
}
}
class NewThread {
public static void Main() {
Demo d = new Demo();
Thread thread = new Thread(new ThreadStart(d.myThread));
thread.Start();
Console.Read();
}
} 출력
My Thread My Thread My Thread