设定的等待消息,并等待光标
问题描述:
WPF VS 2010 C#设定的等待消息,并等待光标
有一个窗口,在后面的代码的开头是收集数据对于需要45秒以上的观点......你会怎么做一个请稍候消息持续到 收集视图。 也有,有什么办法有一个等待光标?
答
加载数据到BackgroundWorker。使用BackroundWorkers ProgressChanged
-event显示进度消息。
// Show here your wait message make a ProgressBar visible
Mouse.OverrideCursor = Cursors.Wait; // Maybe you only want to set the cursor of the window. Then change this line code (and the reset)
BackgroundWorker bgWorker = new BackgroundWorker() { WorkerReportsProgress=true};
bgWorker.DoWork += (s, e) => {
// Load here your file/s
// Use bgWorker.ReportProgress(); to report the current progress
};
bgWorker.ProgressChanged+=(s,e)=>{
// Here you will be informed about progress and here it is save to change/show progress. You can access from here savely a ProgressBars or another control.
};
bgWorker.RunWorkerCompleted += (s, e) => {
// Here you will be informed if the job is done. Close here your wait message or hide your progressbar
Mouse.OverrideCursor = null;
};
bgWorker.RunWorkerAsync();
由于装载作业现在运行的异步,你必须确保你的用户界面不会让用户做的事情,是在当前的应用程序状态(加载)无效。最简单的方法是,将IsEnabled
-property设置为false
的窗口禁用。
+0
不错,非常好谢谢 – ramnz 2010-09-14 22:22:11
请不要使用“C#4.0”标签,除非问题是特定于该版本的C#语言。 – 2010-09-14 18:28:01
我会,对不起,不知道 – ramnz 2010-09-14 22:24:02