【发布时间】:2016-01-18 13:41:30
【问题描述】:
我有以下代码:
Thread thread = new Thread(new ThreadStart(CreateSplashScrn));
thread.SetApartmentState(ApartmentState.STA);
thread.IsBackground = true;
thread.Start();
OpenSplashScrn();
ChangeSplashScrnMessageText("String");
public void CreateSplashScrn()
{
splash = new SplashScreen(this);
System.Windows.Threading.Dispatcher.Run();
}
public void OpenSplashScrn()
{
splash.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
new Action(() => { splash.Show(); }));
}
public void ChangeSplashScrnMessageText(string messageText)
{
splash.messageLabel.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
new Action(() => { splash.messageLabel.Content = messageText; }));
}
但是,这会在 OpenSplashScrn() 处返回空引用异常。 如何在另一个线程中打开它并更改标签内容? 这可以通过任务完成吗?
【问题讨论】:
-
为什么要在另一个线程中打开闪屏?
标签: c# wpf multithreading splash-screen