当我让大数据用户知道该方法正在运行而不冻结时如何进行?
我有一个可能需要很长时间才能完成的方法。我想防止我的程序在该方法运行时冻结。
我可以做什么来向用户显示正在运行该方法(例如进度条)?
I have a method that may take a long time to finish. I want to prevent my program from freezing while this method is running.
What can I do to show the user it is running the method (for example a progress bar)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,正如 HB 所说,如果该方法在某个后台线程中异步运行,那么您的 UI 不会冻结。
如果您希望 UI 上有一个进度条,可以告诉用户已完成多少进度,那么您可以使用 ReportProgress BackgroundWorker
First of all as H.B said if the method is running asynchronously in some background thread then your UI won't freeze.
If you want a progress bar on your UI that can tell user how much progress has completed then you can use ReportProgress functionality of a BackgroundWorker
您应该使用BackgroundWorker 类。它比纯线程更好,因为它做了一些额外的事情。现在记不清了,那是我做 WPF 的很长一段时间了。这段代码将帮助您:
You should use BackgroundWorker class. Its better then pure threads because it does some additional stuff. Cant remember right now, that was a long time I have done WPF. This code will help you: