私のプロジェクトには 3 つのクラスと 2 つのスレッドがあります。スレッドが作成されたクラスのプロパティにアクセスすると、正しい値が得られます。私が読んでいるクラスは、2 番目のスレッドを開始します。この新しいスレッドから、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());
}
}