110,534
社区成员
发帖
与我相关
我的任务
分享
class Program
{
static Object[] ThreadManager = new object[3];
static void Main(string[] args)
{
Thread t1 = new Thread(new ThreadStart(Function1));
t1.Start();
ThreadManager[0] = t1;
Thread t2 = new Thread(new ThreadStart(Function2));
t2.Start();
ThreadManager[1] = t2;
Thread t3 = new Thread(new ThreadStart(Function3));
t3.Start();
ThreadManager[2] = t3;
string strTemp = String.Empty;
Thread tt2 = (Thread)ThreadManager[2];
while (true)
{
System.Console.WriteLine("main thread...输入命令......");
strTemp = System.Console.ReadLine();
if (strTemp == "1")
{
try
{
tt2.Suspend();
}
catch(Exception ex)
{
string str = ex.ToString();
}
System.Console.WriteLine("Function [3] Suspend......");
}
else if (strTemp == "2")
{
tt2.Resume();
System.Console.WriteLine("Function [3] Resume......");
}
else
{
Thread.Sleep(500);
continue;
}
}
}
static void Function1()
{
while (true)
{
System.Console.WriteLine("Function [1] run......");
Thread.Sleep(3000);
}
}
static void Function2()
{
while (true)
{
System.Console.WriteLine("Function [2] run......");
Thread.Sleep(3000);
}
}
static void Function3()
{
while (true)
{
System.Console.WriteLine("Function [3] run......");
Thread.Sleep(3000);
}
}
}