我试图编译以下代码:
public class SplashScreenManager
{
private static readonly object mutex = new object();
public static ISplashScreen CreateSplashScreen(Stream imageStream, Size imageSize)
{
object obj;
Monitor.Enter(obj = SplashScreenManager.mutex);
ISplashScreen vm2;
try
{
SplashScreenWindowViewModel vm = new SplashScreenWindowViewModel();
AutoResetEvent ev = new AutoResetEvent(false);
Thread thread = new Thread(delegate
{
vm.Dispatcher = Dispatcher.CurrentDispatcher;
ev.Set();
Dispatcher.CurrentDispatcher.BeginInvoke(delegate //<- Error 2 here
{
SplashForm splashForm = new SplashForm(imageStream, imageSize)
{
DataContext = vm
};
splashForm.Show();
}, new object[0]);
Dispatcher.Run();
});
thread.SetApartmentState(ApartmentState.STA);
thread.IsBackground = true;
thread.Start();
ev.WaitOne();
vm2 = vm;
}
finally
{
Monitor.Exit(obj);
}
return vm2;
}
}
并得到错误:
以下方法或属性之间的调用不明确:“System.Threading.Thread.Thread(System.Threading.ThreadStart)”和“System.Threading.Thread.Thread(System.Threading.ParameterizedThreadStart)”
Edit1: 我更正了代码并得到错误 2:
无法将匿名方法转换为类型“System.Windows.Threading.DispatcherPriority”,因为它不是委托类型