这是我的测试代码:
class Program
{
static void Main(string[] args)
{
new Thread(delegate() { runThread(); }).Start();
Console.WriteLine(Global.test);
Console.ReadKey();
}
private static void runThread()
{
Console.WriteLine("this is run thread");
Global.test = "this is test from thread";
Console.WriteLine(Global.test);
}
}
public class Global
{
public static string testV { get; set; }
}
我希望能够用线程设置“testV”值。看起来 Thread 确实设置了值,但是当从 main 方法中检索 testV 值时,它什么也没给出。这是为什么?