C# 窗口在繁忙时变为空白 ->进度条?但如何呢?

发布于 2024-11-30 22:57:41 字数 195 浏览 0 评论 0原文

我有一个程序可以执行一些复制作业(通过 File.Copy),可能会持续几分钟。当用户此时将另一个窗口带到前台时,程序窗口会变为空白,因为它不会重新绘制自身。

现在我想在屏幕中央的额外窗口中显示进度栏,但该窗口也是空白的。

所以我在另一个线程中启动它,但没有帮助。

我很确定以前有人这样做过,但我找不到有效的例子。有什么想法吗?

I have a program which does some copy jobs (via File.Copy) that could last a few minutes. When the user brings another window to foreground in this time the program window gets blank since it doesn't redraw itself.

Now I want to show a ProgressBar in an extra window in the center of the screen, but that window get's blank too.

So I startet it in another thread which didn't help.

I'm quite sure someone did this before but I cannot find a working example. Any Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

墨小墨 2024-12-07 22:57:41

BackgroundWorker 类 的文档中有一个很好的示例。

There is nice example in the documentation on BackgroundWorker class.

季末如歌 2024-12-07 22:57:41

克里斯F是正确的。您的长时间操作应在 BackgroundWorker 线程中完成。您可以使用BackgroundWorker 报告进度,并将其连接到表单上的进度栏。

ChrisF is correct. Your long operation should be done in a BackgroundWorker thread. You can use BackgroundWorker to report progress, and hook that up to a progress bar on your form.

笨笨の傻瓜 2024-12-07 22:57:41

您需要使用 BackgroundWorker。还有其他方法可以线程化操作,但这一种可能是最简单的,并且将继续在前台执行消息泵送,因此 Windows 不会认为您的应用程序已停止响应。

另一种选择是使用Thread,并使用< code>Thread.Join 等待后台任务完成,因为 Thread.Join 在等待时还会向 Windows 发送标准消息泵信息。

You need to thread your operation using a BackgroundWorker. There are other ways to thread the operation, but this one is probably the simplest, and will continue to perform message pumping in the foreground so Windows doesn't think your application has stopped responding.

Another option would be to use a Thread, and use Thread.Join to wait for the background task to complete, since Thread.Join also sends standard message pump information to Windows while it waits.

夏有森光若流苏 2024-12-07 22:57:41

您可以使用BackgroundWorker 类。

请参阅此答案。

You can use BackgroundWorker class.

See this answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文