错误:无法将类型'void'隐式转换为'System.Threading.Thread'[复制]

问题描述 投票:-2回答:1

下面的代码演示了创建执行相同作业的线程的两种方法,但只有一种方法有效,而另一方则无效。从我看到的差异是变量的声明 - 有人可以帮助解释为什么这会导致Error: Cannot implicitly convert type 'void' to 'System.Threading.Thread'

public MainWindow()
{
    InitializeComponent();

    // Runs OK
    new Thread(() => { MessageBox.Show("foo");}).Start();

    // Error: Cannot implicitly convert type 'void' to 'System.Threading.Thread'
    Thread t = new Thread(() =>  { MessageBox.Show("foo”); }).Start();
}
c# wpf multithreading
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.