C#中简单实现多线程
2006-04-16 09:37
447 查看
感觉用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);
}
}
}
}
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);
}
}
}
}
相关文章推荐
- C#实现异步编程的两个简单机制(异步委托&定时器)及Thread实现多线程
- C#实现一个简单的多线程IP或端口扫描器
- C# winform窗体实现简单打印
- 使文件下载的自定义连接支持 FlashGet 的断点续传多线程链接下载! C#/ASP.Net 实现
- WPF学习——制作一个简单的录入界面(2):用C#编程实现所有控件的功能
- Java多线程-一个简单的线程,实现挂起和恢复的功能
- Excel与XML相互转换 - C# 简单实现方案
- C#仿QQ面板的简单实现
- c#实现简单工厂—数据库连接
- 【翻译】C#中使用BackgroundWorker实现多线程
- [C#基础教程之]C# 实现多线程的同步方法详解
- c#利用反射+特性实现简单的实体映射数据库操作类实现自动增删改查(三)带源码写好的持久层
- 一起谈.NET技术,用C#实现HTTP协议下的多线程文件传输
- 用C#实现HTTP协议下的多线程文件传输--转载
- spring+ActiveMQ+JMS+线程池实现简单的分布式,多线程,多任务的异步任务处理系统
- 用C#实现HTTP协议下的多线程文件传输(转)
- iOS多线程的简单实现方式
- C# 多页打印简单实现
- 利用.net(C#)执行sql脚本的简单实现
- Qt---多线程的简单实现