C#调度程序和进度条被阻止

时间:2016-11-14 16:01:42

标签: c# wpf progress-bar dispatcher

我是C#的新手,我想在执行Dispatcher.BeginInvoke期间显示一个带有不确定进度条的加载窗口,我尝试这样的事情:

progressbarwin = new Windows1();
Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.ContextIdle, (Action)delegate
     {
       //Do something
        progressbarwin.Close();
     });

progressbarwin.ShowDialog();

显示窗口(在委托之前),但进度条被阻止。我该怎么办?

@Sinatr 我试图从新的线程UI中打开Windows:

Thread loadT = new Thread(new ThreadStart(() =>
{
    Loading progressbarwin = new Loading();
    progressbarwin.ShowDialog();
}));
// Set the apartment state
loadT.SetApartmentState(ApartmentState.STA);
// Make the thread a background thread
loadT.IsBackground = true;
// Start the thread
loadT.Start();
//Do something
loadT.Abort();

但是当我创建窗口时,它给了我一个跨线程异常(new Loading())

@Mitra M. 它是一样的:(

0 个答案:

没有答案