在 dotnet windows 窗体中,如何在窗体中暂停而不使窗体线程进入休眠状态?

发布于 2024-10-06 06:34:52 字数 141 浏览 1 评论 0原文

问题是我不想使用 Threading.Sleep(1000) 因为我需要线程保持活动状态,只需在执行下一行代码之前暂停,同时不允许用户在暂停期间单击表单上的任何内容。我能想到的最简单的方法是打开一个不透明度为 0 的定时自动关闭对话框。有更好的方法来获得相同的结果吗?

Problem is I do not want to use Threading.Sleep(1000) because I need the thread to stay alive, just pause before executing the next line of code while disallowing the user to click anything on the form during the pause. The simplest method I could think of was to open a timed self-closing dialog with an opacity of 0. Any better way to get the same result?

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

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

发布评论

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

评论(3

对你再特殊 2024-10-13 06:34:52

您可以设置 Enabled = false;< /code>并稍后使用计时器将其设置为 true

You can set Enabled = false; and use a timer to set it to true later on.

云归处 2024-10-13 06:34:52

将 Enabled 设置为 false,然后一段时间后将其设置回 true。您可以在单独的线程上执行此操作。还可以考虑将光标更改为等待光标。

Set Enabled to false, and then some time later set it back to true. You might do this on a separate thread. Also consider changing the cursor to a wait cursor.

骑趴 2024-10-13 06:34:52

有几种方法:

  • 禁用整个表单,进行处理并再次启用它。 (使用 Form.Enabled 属性。)

  • 显示一个模式对话框,没有关闭它或移动它(完全锁定)的选项,并带有类似“正在加载”或“正在处理”的消息,请执行以下操作 。

There are a few ways :

  • Disable the entire form, do your processing and enable it back again. (Use Form.Enabled property.)

  • Show a modal dialog with no options to close it or move it (completely locked down) with a message something like 'Loading' or 'Processing', do your stuff and close it.

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