我正在尝试转换此堆栈溢出问题中的C#代码,以便在VB.NET中使用。我正在使用.NET Framework 4.0。 WPF wait window
以下是代码:
Thread thread = new Thread(() =>
{
Window1 w = new Window1();
w.Show();
w.Closed += (sender2, e2) =>
w.Dispatcher.InvokeShutdown();
System.Windows.Threading.Dispatcher.Run();
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
答案 0 :(得分:4)
您可以在VB中创建一个lambda表达式,如下所示:
Dim thread As New Thread(Sub()
' ...
End Sub)
VB.NET对于匿名方法没有单独的语法,比如C#,但VB.NET中的lambda表达式的语法看起来更类似于C#匿名方法而不是C#lambda表达式。
答案 1 :(得分:3)
您可能需要阅读Lambda Expressions in VB.NET
Dim threadSub = Sub()
...
End Sub
Dim thread As New Thread(threadSub)
答案 2 :(得分:2)
Dim thread As New Thread(Sub()
Dim w As New Window1()
w.Show()
AddHandler w.Closed, Sub(sender2, e2) w.Dispatcher.InvokeShutdown()
System.Windows.Threading.Dispatcher.Run()
End Sub)
thread.SetApartmentState(ApartmentState.STA)
thread.Start()