在对话框中显示进度
我有一个需要很长时间的过程,我想要一个窗口来显示进度。但是,我不知道如何显示进度。
代码如下:
if (procced)
{
// the wpf windows :
myLectureFichierEnCour = new LectureFichierEnCour(_myTandemLTEclass);
myLectureFichierEnCour.Show();
bgw = new BackgroundWorker();
bgw.DoWork += startThreadProcessDataFromFileAndPutInDataSet;
bgw.RunWorkerCompleted += threadProcessDataFromFileAndPutInDataSetCompleted;
bgw.RunWorkerAsync();
}
并且:
private void startThreadProcessDataFromFileAndPutInDataSet(object sender, DoWorkEventArgs e)
{
_myTandemLTEclass.processDataFromFileAndPutInDataSet(
_strCompositeKey,_strHourToSecondConversion,_strDateField);
}
我可以调用 _myTandemLTEclass.processProgress
来获取进度提示。
I have a process that takes a long time, and I want a window to show the progress. But, I can't figure how to display the progress.
Here's the code:
if (procced)
{
// the wpf windows :
myLectureFichierEnCour = new LectureFichierEnCour(_myTandemLTEclass);
myLectureFichierEnCour.Show();
bgw = new BackgroundWorker();
bgw.DoWork += startThreadProcessDataFromFileAndPutInDataSet;
bgw.RunWorkerCompleted += threadProcessDataFromFileAndPutInDataSetCompleted;
bgw.RunWorkerAsync();
}
And:
private void startThreadProcessDataFromFileAndPutInDataSet(object sender, DoWorkEventArgs e)
{
_myTandemLTEclass.processDataFromFileAndPutInDataSet(
_strCompositeKey,_strHourToSecondConversion,_strDateField);
}
I can call _myTandemLTEclass.processProgress
to get a hint of the progress.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该处理
ProgressChanged
事件并更新用户界面中的进度栏。在执行该工作的实际函数(
DoWork
事件处理程序)中,您将使用指定的参数调用BackgroundWorker
实例的ReportProgress
方法完成的任务量。MSDN Library 中的BackgroundWorker 示例是一段简单的代码完成这项工作的片段。
You should handle the
ProgressChanged
event and update the progress bar in your user interface there.In the actual function that does the work (
DoWork
event handler), you'll call theReportProgress
method of theBackgroundWorker
instance with an argument specifying the amount of task completed.The BackgroundWorker example in MSDN Library is a simple code snippet that does the job.
您的backgroundWorker线程需要处理
DoWork
方法和ProgressChanged
。您还需要确保将
WorkerReportsProgress
标志打开为 true(默认情况下关闭)。参见示例代码:
Your backgroundWorker thread needs to handle the
DoWork
method andProgressChanged
.You also need to make sure you turn on the
WorkerReportsProgress
flag to true (off by default).See example code: