如何在 WPF 中显示数据库操作的进度条?
我想向我的应用程序用户显示以下操作的进度条:
- 当他们在 WPF 中提供登录信息并点击“提交/确定”时。
- 当他们从数据库请求任何信息时(选择命令执行)。
谢谢
I want to show my application user a progressbar for following actions:
- when they provide login information in WPF and hit submit/OK whatever.
- when they request any information from DB (select command execution).
Thank You
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
登录数据库是一个原子操作。所以你不能真正显示进度条。您可以显示等待指示器(沙漏),或不确定的进度条 > (实际上只是一个看起来像进度条的等待指示器)。
对于获取数据的查询,您可以通过对结果集进行分页来显示进度。根据您使用的数据库/ORM,有多种方法可以执行此操作。总体原理是设置一个工作线程,一次抓取一页数据。抓取页面后,将上下文切换到 UI 线程并更新屏幕以显示抓取的数据量。
A login to the database is an atomic operation. So you can't really show a progress bar. You can show a waiting indicator (hour glass), or an indeterminate progress bar (which is really just a waiting indicator that looks like a progress bar).
For a query that gets data, you can show progress by paging the result set. There are multiple ways to do this depending on the database/ORM you use. The general principle is to set up a worker thread and grab data one page at a time. After you grab a page, switch context to the UI thread and update the screen to show how much data you grabbed.