C#:OnClosing 需要一段时间,如何显示带有选取框进度条的对话框?
我必须在 OnClosing 处理程序中进行大量清理,这使得我的应用程序看起来像是挂起的。
如何显示带有字幕式进度条的小对话框,以便用户至少知道它仍在“工作”?
基本上我想开始对话, 继续执行我所有的关闭程序,完成后, 关闭进度对话框。
I have to do quite some cleanup in my OnClosing handler, which makes it seem like my app is hanging.
How can I show a small dialog with a marquee-style progressbar so users will at least know it's still 'working' ?
Basicly I want to start the dialog,
proceed with all my shutdown-procedures and when that's done,
close the progress-dialog.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有很多方法可以实现此目的,但其中一种可能如下所示:
在表单的 OnClosing 方法中,在包含
ProgressBar
及其Style 的单独线程上打开一个“关闭对话框”
属性设置为Marquee
。然后继续执行保存/关闭程序,完成后关闭“关闭”对话框。重要的是,带有选取框的表单必须位于与正在完成工作的线程不同的线程上。否则它不会产生动画,并且应用程序仍然会显得没有响应。
There are many ways to achieve this, but one could looke like this:
In the OnClosing method of your form, open a "shutting down dialog" on a separate thread containing a
ProgressBar
with itsStyle
property set toMarquee
. Then go on and do your saving/closing down procedure, and when you are done, close the "shutting down" dialog.The important thing is that the form with the marquee must be on a separate thread than the one where the work is being done. Otherwise it will not animate, and the app will still appear as if it is not responding.
你有没有尝试过类似的事情:
Have you tried something like: