让后台工作者刷新启动屏幕

发布于 2024-09-03 09:42:48 字数 258 浏览 4 评论 0原文

理论上是否可以在类中使BackgroundWorker定期刷新现有的启动屏幕表单,或者这是不可能的? (我知道这可能是糟糕的设计,但目前我没有看到任何更好的方法。)

请记住:

  1. 我不希望后台工作人员进行加载,因为它很难实现。< /p>

  2. 我无法使用内置的启动屏幕支持

  3. 我知道 DoEvents 替代方案,但我不想走这条路,它会非常也很难实现,而且不可靠。

Would it be theoretically possible to make BackgroundWorker in a class to periodically refresh existing splash screen form, or is that impossible? (I know that it's probably bad design, but currently I do not see any better way.)

Please keep in mind that:

  1. I do not want the background worker to do the loading as it would be terribly hard to implement.

  2. I can't use the inbuilt splash screen support

  3. I'm aware of DoEvents alternative but I do not want to go this path, it would very hard to implement as well, and not reliable.

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

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

发布评论

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

评论(1

早茶月光 2024-09-10 09:42:48

这绝对是可能的,如果这不完全是BackgroundWorker 的目的(主要是在长时间运行的后台进程发生时刷新前台GUI),那么它已经非常接近了。

如果您尝试在应用程序加载或安装时尝试执行一些操作,例如使初始屏幕在图像或文本中旋转,请考虑仅放置 计时器 启动,并在计时器滴答声上刷新。

明智的做法是远离 DoEvents,这乍一看似乎是最简单的解决方案,但会导致痛苦和间歇性的、难以调试的问题。

编辑:从您的评论来看,您似乎正在启动画面的 GUI 线程上加载应用程序,这导致启动画面无法自行刷新。这是预期的行为。您需要使用裸线程或BackgroundWorker(专为这种情况而设计)将应用程序负载放到后台线程上。我敢打赌这并不像您期望的那么难。如果您在使用该方法时遇到问题,请随时发布问题寻求帮助。

It is absolutely possible, and if it's not quite what BackgroundWorker was intended for (primarily, refreshing a foreground GUI while a long-running background process is taking place), it's pretty darned close.

If you're trying to do something like make a splash screen rotate through images or text while your application or loading or installing, consider just putting a timer on the splash, and refreshing on timer tick.

You're wise to stay away from DoEvents, which seems the simplest solution at first, but leads to pain and intermittent, hard-to-debug problems down the road.

Edit: From your comments, it looks like you're loading your application on the splash screen's GUI thread, and that's causing your splash form to not refresh itself. This is expected behavior. You'll want to put your application load onto a background thread, using bare threading or BackgroundWorker (which is designed for exactly this situation). I'll bet it's not as difficult to do as you're expecting it to be. If you're having problems with that approach, feel free to post a question asking for help.

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