后台任务的进度报告

编程入门 行业动态 更新时间:2024-10-23 07:34:11
本文介绍了后台任务的进度报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个后台任务,将文件导入数据库.我希望用户查看正在发生的事情(收集文件/导入文件),当前正在处理的文件以及任务已进行了多长时间.我该如何轻松地做到这一点? 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)

更多推荐

后台任务的进度报告

本文发布于:2023-11-15 05:46:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1591678.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进度   后台   报告

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!