>  기사  >  백엔드 개발  >  간단한 스레드를 생성하는 C# 프로그램

간단한 스레드를 생성하는 C# 프로그램

PHPz
PHPz앞으로
2023-09-10 16:49:121097검색

创建简单线程的 C# 程序

스레드를 생성하기 위해 함수를 생성했습니다. -

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));

Example

다음 코드를 사용하여 간단한 스레드를 생성합니다.

실시간 데모

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();
   }
}

Output

My Thread
My Thread
My Thread

위 내용은 간단한 스레드를 생성하는 C# 프로그램의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제