在 dotnet windows 窗体中,如何在窗体中暂停而不使窗体线程进入休眠状态?
问题是我不想使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以设置
Enabled = false;< /code>
并稍后使用计时器将其设置为
true
。You can set
Enabled = false;
and use a timer to set it totrue
later on.将 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.
有几种方法:
禁用整个表单,进行处理并再次启用它。 (使用
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.