C#マルチスレッドプログラムで不正な動作が発生しています。私の静的メンバーの一部は他のスレッドで値を失っていますが、同じ宣言型の一部の静的メンバーは値を失っていません。
public class Context {
public Int32 ID { get; set; }
public String Name { get; set; }
public Context(Int32 NewID, String NewName){
this.ID = NewID;
this.Name = NewName;
}
}
public class Root {
public static Context MyContext;
public static Processor MyProcessor;
public Root(){
Root.MyContext = new Context(1,"Hal");
if(Root.MyContext.ID == null || Root.MyContext.ID != 1){
throw new Exception("Its bogus!") // Never gets thrown
}
if(Root.MyContext.Name == null || Root.MyContext.Name != "Hal"){
throw new Exception("It's VERY Bogus!"); // Never gets thrown
}
Root.MyProcessor = new MyProcessor();
Root.MyProcessor.Start();
}
}
public class Processor {
public Processor() {
}
public void Start(){
Thread T= new Thread (()=> {
if(Root.MyContext.Name == null || Root.MyContext.Name != "Hal"){
throw new Exception("Ive lost my value!"); // Never gets Thrown
}
if(Root.MyContext.ID == null){
throw new Exception("Ive lost my value!"); // Always gets thrown
}
});
}
}
これは、特定のタイプの静的メンバーを使用しているときのスレッドミューテーションの問題ですか?