我在App_Startup加载主窗口()。我想显示进度条,同时加载窗口。但它不工作:
无效App_Startup(对象发件人,StartupEventArgs E)
{
螺纹bootStrapThread =新主题(新的ThreadStart(runBootStrapProcess));
bootStrapThread.SetApartmentState(ApartmentState.STA);
bootStrapThread.IsBackground = TRUE;
bootStrapThread.Start();
_loadingProgressBar =新loadingProgressBar();
_loadingProgressBar.ShowDialog();
}
我想从线程加载窗口:
无效runBootStrapProcess()
{
MetadataReader MR =新MetadataReader();
如果(currentVersionNo.Equals(remoteVersionNo))
{
Application.Current.Shutdown();
}
其他
{
主窗口MW =新的主窗口();
mw.Show();
}
_loadingProgressBar.ShouldCloseNow = TRUE;
}
解决方案
您可以试试这个:
无效runBootStrapProcess(){
MetadataReader MR =新MetadataReader();
如果(currentVersionNo.Equals(remoteVersionNo)){
Application.Current.Shutdown();
} 其他 {
System.Windows.Application.Current.Dispatcher.BeginInvoke(
新的行动(
()=> {
主窗口MW =新的主窗口();
mw.Show();
}));
}
_loadingProgressBar.ShouldCloseNow = TRUE;
}
您基本上从线程当你想显示窗口发送到主应用程序线程。因此,这会阻止逼抢的应用程序,当线程退出,因为主窗口
从主线程所示。
I am loading MainWindow in App_Startup (). I wanted to show the progress bar while loading the window. But it is not working :
void App_Startup(object sender, StartupEventArgs e)
{
Thread bootStrapThread = new Thread(new ThreadStart(runBootStrapProcess));
bootStrapThread.SetApartmentState(ApartmentState.STA);
bootStrapThread.IsBackground = true;
bootStrapThread.Start();
_loadingProgressBar = new loadingProgressBar();
_loadingProgressBar.ShowDialog();
}
I want to load the window from thread :
void runBootStrapProcess()
{
MetadataReader mr = new MetadataReader();
if (currentVersionNo.Equals(remoteVersionNo))
{
Application.Current.Shutdown();
}
else
{
MainWindow mw = new MainWindow();
mw.Show();
}
_loadingProgressBar.ShouldCloseNow = true;
}
解决方案
You can try this:
void runBootStrapProcess() {
MetadataReader mr = new MetadataReader();
if (currentVersionNo.Equals(remoteVersionNo)) {
Application.Current.Shutdown();
} else {
System.Windows.Application.Current.Dispatcher.BeginInvoke(
new Action(
() => {
MainWindow mw = new MainWindow();
mw.Show();
}));
}
_loadingProgressBar.ShouldCloseNow = true;
}
You basically from the thread when you want to show the window send it to the main application thread. This thus stops the application from closing down when the thread exits since the MainWindow
is Shown from the main thread.
上一篇:C#SQLite的连接字符串格式字符串、格式、SQLite
下一篇:要启用扩展,请验证它们是否已在这些 .ini 文件中启用 - Vagrant/Ubuntu/Magento 2.0.2已在、文件、ini、Vagrant