后台任务的进度报告 [英] Progress reporting from background task

查看:101
本文介绍了后台任务的进度报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个后台任务,将文件导入数据库.我希望用户查看正在发生的事情(收集文件/导入文件),当前正在处理的文件以及任务已进行了多长时间.我该如何轻松地做到这一点? Model和Controller之间的交互是如此紧密,以至于我几乎可以将导入代码放入窗口的代码文件中,并直接更改进度条值等.你怎么认为?您将如何解决这个问题?

I have a background task that imports files into a database. I want the user to see what is currently happening (collecting files/ importing files), which file is currently processed and how far the task has progressed. How can I do this in an easy way? The interaction between Model and Controller is so close, that I could almost put the importing code into the window's code file and change the progress bar value etc. directly. What do you think? How would you solve this problem?

推荐答案

使用 BackgroundWorker ,非常适合此任务.它可以使用ReportProgress方法将当前进度通知UI,这将在UI线程上引发ProgressChanged事件(这意味着您不必担心跨线程调用和Invoke)

Use a BackgroundWorker, it's perfect for this task. It can notify the UI of current progress using the ReportProgress method, which raises the ProgressChanged event on the UI thread (which means you don't have to worry about cross-thread calls and Invoke)

这篇关于后台任务的进度报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆