image

编辑人: 沉寂于曾经

calendar2025-05-09

message4

visits370

使用C#编写创建一个线程的代码?

using System;
using System.IO;
using System.Threading ;
class MyThread{
 public int count;
 string thrdName;
 public MyThread(string name){
  count=0;
  thrdName=name;
 }
 public void run(){
  Console.WriteLine(thrdName+”starting.”);
  do{
   Thread.Sleep(500);
   Console.WriteLine(“In”+thrdName+”, count is “+count);
   count++;
  }while(count<10);  
 Console.WriteLine(thrdName+” terminating.”);
 }
}
class MultiThread{
 public static void Main(){
  Console.WriteLine(“Main thread starting.”);
  MyThread mt=new MyThread(“Child #1”);
  Thread newThrd=new Thread(new ThreadStart(mt.run));
  newThrd.Start();
  do {
   Console.Write(“.”);
   Thread.Sleep(100);
  }while(mt.count!=10);
  Console.WriteLine(“Main thread ending.”);
 }
}

喵呜刷题:让学习像火箭一样快速,快来微信扫码,体验免费刷题服务,开启你的学习加速器!

创作类型:
原创

本文链接:使用C#编写创建一个线程的代码?

版权声明:本站点所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明文章出处。
分享文章
share