如何在处理大量数据时保持响应式 UI? [英] How do I keep a responsive UI while processing large amounts of data?

查看:21
本文介绍了如何在处理大量数据时保持响应式 UI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建 winform 来处理(将 txt 文件转换为 tiff)大量文件.我把所有的代码放在一个按钮后面(btnProcess).这是一个好主意吗?它有效,但我注意到当我离开 winform 并回到此时,我看到空白窗口,直到该过程完成.我听说过后台工作人员.后台工作者的目的是什么?

I am creating winform to process (convert txt files to tiff) large amount of files. I put all the code behind a button (btnProcess). Is this a good idea? It works but I noticed when I go away from the winform and come back to this I see blank window until the process is complete. I heard about background worker. what is the purpose of background worker?

推荐答案

这里你需要的是多线程.这意味着两个(或更多)代码线程将并行运行.其中之一是 UI 线程,负责绘制窗口的线程.在您的情况下,您在 UI 线程中运行代码,因此在代码运行时阻止了 UI 呈现.

What you need here is multi-threading. That means that two (or more) threads of code would run in parallel. One of them would be the UI thread, the one responsible for drawing the window. In your case you are running your code in the UI thread and thus blocking the UI rendering while your code is running.

BackgroundWorker 的目的是启动对新线程的操作,这正是您所需要的.

The purpose of the BackgroundWorker is to start an operation on a new thread and is what you need.

这篇关于如何在处理大量数据时保持响应式 UI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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