在vb.net中留下时间延迟
我有一个表单,在每行执行之前我需要给予 3 秒的时间延迟。但是当我尝试 system.threading.thread.sleep 时,它会冻结 UI,而且所有延迟都作为一个延迟执行。 也就是说,
如果我让
label.text = "intializing..."
sleep(5000)
label1.text = "connectinh..."
sleep(5000)
label2.text = "connected..."
sleep(5000)
UI 完全冻结 15 秒,然后所有执行都会立即发生,就好像它们之间没有延迟语句一样。除了 threading.sleep 之外我找不到其他任何东西。
I have a form in which I need to give timedelay of 3 seconds before each line executes. But when I try system.threading.thread.sleep it's freezing the UI and furthermore all delays are executing as one single delay.
that is
if I have
label.text = "intializing..."
sleep(5000)
label1.text = "connectinh..."
sleep(5000)
label2.text = "connected..."
sleep(5000)
the UI freezes for 15 seconds totally and then all executiong happens instantaneously as if there was no delay statement between them. I was not able to find out anything else other than threading.sleep.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
罗恩说的话:
What Ron said:
内联解决方案,无多线程,无计时器。
an inline solution, no multi-threading, no timers.
您需要在单独的事件中更新每个标签,并让它刷新 UI。
创建一个计时器,它将调用您的事件处理程序并在其中每次更新不同的标签
You need to have each label update in a separate event and let it refresh the UI.
Create a timer that will call your event handler and in it update a different label every time
请尝试以下操作:
Application.DoEvents 告诉操作系统进程底层工作,例如更新文本值。
Try the following:
Application.DoEvents tells the OS process underlying work, such as updating the text value.
我认为这应该比 DoEvents 工作得更正常!
I think this should work more properly than DoEvents!