c#的线程问题
来源:百度知道 编辑:UC知道 时间:2024/05/27 03:37:10
请高手指点一二...虚心学习!
用静态变量作为一个线程的要提交的变量
我写了个简单的示例
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Thread thread1 = new Thread(new ThreadStart(Thread1));
Thread thread2 = new Thread(new ThreadStart(Thread2));
thread1.Start();
while (Threadpara1.isFinish==false)
{}
thread2.Start();
}
public void Thread1()
{
Threadpara1.time = DateTime.Now;
Threadpara1.isFinish = true;
}
public void Thread2()
{
Threadpara2.time = Threadpara1.time.AddSeconds(10);
}
}
public class Threadpara1
{
public static DateTime