之間的曖昧我試圖編譯下面的代碼:電話是的ThreadStart和ParameterizedThreadStart
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;
}
}
,並得到了錯誤:
The call is ambiguous between the following methods or properties: 'System.Threading.Thread.Thread(System.Threading.ThreadStart)' and 'System.Threading.Thread.Thread(System.Threading.ParameterizedThreadStart)'
EDIT1: 我糾正代碼,並得到錯誤2 :
無法將匿名方法轉換爲鍵入'System.Windows.Threading。 DispatcherPriority「,因爲它不是委託類型
見我提供用於固定代碼爲.NET 3.5以及4 – chrisw 2013-04-24 09:21:38