我有一个主机类,它在新线程上启动另一个类的实例,如下所示:
我正在参考这篇 MSDN 文章,根据该文章,Class2.P1 不应为空。链接:http: //msdn.microsoft.com/en-us/library/system.threading.threadstart.aspx
我错过了什么明显的东西吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            new Host().DoWork();
        }
    }
    public class Host {
      Class2Parent c = new Class2();
      Thread t;
      public void DoWork() {
      c.P1 = new Class3();
      t = new Thread(c.Start);
      t.Start();
      }
    }
    public class Class2Parent {
      public Class3 P1 = null;
        public virtual void Start() {}
    }
   public class Class2 : Class2Parent {
       public Class3 P1 = null;          
       public override void Start() {
      Console.WriteLine(P1 == null); // this is always true
      } 
   }   
   public class Class3 
   {}
}