【发布时间】:2013-08-09 10:37:56
【问题描述】:
我的项目有 3 个类和 2 个线程。当我访问创建线程的类的属性时,我得到了正确的值。我正在阅读的课程开始第二个线程。我想从这个新线程中读取第二类的属性。
当我在class1中设置值时,值为1,但class3中的值为0。
class test
{
public void main()
{
Class2 cl = new Class2;
thread th = new thread(new threadstart(a.start));
th.start()
cl.test=1;
}
}
class Class2
{
private int test;
public int test
{
get { return test;}
set {test = value;}
}
public void start()
{
Class3 cls = new Class3();
thread th = new thread(new threadstart(cls.begin));
th.start();
}
}
class Class3
{
public void begin()
{
Class2 cl = new Class2();
MessageBox.show(cl.test.tostring());
}
}
【问题讨论】:
-
您的意思是在
test::main中输入cl.start而不是a.start
标签: c# multithreading instantiation instance-variables