C# 线程间通讯与控制
来源:百度知道 编辑:UC知道 时间:2024/09/24 13:13:14
使用Thread的Suspend方法可以暂停一个线程,Resume继续,给你写个例子吧
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static Thread th1;
static Thread th2;
static int value = 0;
static void Main(string[] args)
{
th1 = new Thread(new ThreadStart(Method1));
th2 = new Thread(new ThreadStart(Method2));
th1.Start();
th2.Start();
}
static void Method1()
{
for (int i = 0; i < 1000000000; i++)
{
value++;
}
Console.WriteLine("完成");
}
static void Method2()
{
while (true)