using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace TestThread
{
class Program
{
static void Main(string[] args)
{
//实例化三个线程对象
Thread one = new Thread(func1);
Thread two = new Thread(func2);
Thread three = new Thread(func3);
//对三个线程实例命名
one.Name = "myThreadone";
two.Name = "myThreadtwo";
three.Name = "myThreadthree";
//分别启动三个线程
one.Start();
two.Start();
three.Start();
//让线程休眠5秒钟
Thread.Sleep(500);
//one.Suspend(); //让线程one挂起
three.Abort(); //线程终止
two.Join(); //线程调用方法
//one.Resume(); //恢复执行one线程
Console.ReadKey();
}
//线程要调用的函数
public static void func1()
{
Console.WriteLine("我是线程一输出的结果。");
}
public static void func2()
{
Console.WriteLine("我是线程2输出的结果。");
}
public static void func3()
{
Console.WriteLine("我是线程3输出的结果。");
}
}
}
C#线程的使用和测试
最新推荐文章于 2022-07-08 08:51:23 发布