
·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> 多线程中变量的内存分配
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Diagnostics;
namespace TestMultiThread
{
class PRogram
{
pp s = new pp();
static void Main(string[] args)
{
Program dd = new Program();
Thread th;
for (int i = 0; i < 10; i++)
{
th= new Thread(new ThreadStart(dd.Test));
th.Name = i.ToString();
th.Start();
Thread.Sleep(10);
}
Console.WriteLine("wait 3 seconds");
Console.ReadKey();
}
public void Test()
{
Int32 i = 0;
i++;
Console.WriteLine("name:{0}/I vaule:{1}", Thread.CurrentThread.Name,i.ToString());
s.ps();
}
}
class pp
{
public void ps()
{
Int32 i=0;
Thread.Sleep(3000);
i++;
Console.WriteLine("ps:name:{0}/i:{1}", Thread.CurrentThread.Name,i.ToString());
}
}
}
测试代码: