html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

C#中简单实现多线程_.NET教程_编程技术

[ ] 已经帮助:人解决问题
多线程

感觉用C#进行开发就是快

using System;
using System.Threading;

namespace ConsoleApplication1
{
 /// <summary>
 /// Class1 的摘要说明。
 /// </summary>
 class Class1
 {
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
   //
   // TODO: 在此处添加代码以启动应用程序
   //
   Thread thread1 = new Thread(new ThreadStart(Method1));
   Thread thread2 = new Thread(new ThreadStart(Method2));
   thread1.Start();
   thread2.Start();
  
  }
  public static void Method1()
  {
   while(true)
   {
    Console.WriteLine("this is thread : 1");
    Thread.Sleep(1000);

   }
  
  }
  public static void Method2()
  {
   while (true)
   {
    Console.WriteLine("this is thread : 2");
    Thread.Sleep(1520);
   }
  

  }
 }
}

DCbHTML5中文学习网 - HTML5先行者学习网
DCbHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助