如何在两行之间添加延迟 [英] How to add delay between two lines
本文介绍了如何在两行之间添加延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在执行两行之间添加延迟意味着我想执行一行然后等待5秒然后执行第二行。 thread.sleep在c#中的windows窗体中运行不正常。还有其他方式吗?
我尝试过:
< pre lang =C#> steps [recursiveStep,left] .BackColor = Color.Fuchsia;
left ++;
Thread.Sleep( 5000 );
步[recursiveStep,left] .BackColor = Color.Green;
解决方案
这很复杂,因为你试图得到一个线程同时做不同的事情:显示正在发生的事情,并在做其他事情之前等待特定的时间产品 - 这是行不通的。
所以设置一个Timer,用户开始第二次换色而不是试图停止当前线程,因为你停止了线程,你看不到任何变化......
How I can add delay between execution of two lines means i want to execute one line and then wait for 5 second and then execute second line. thread.sleep is not working well in windows form in c#. Is any other way?
What I have tried:
steps[recursiveStep, left].BackColor = Color.Fuchsia;
left++;
Thread.Sleep(5000);
steps[recursiveStep, left].BackColor = Color.Green;
解决方案
It's complicated, because you are trying to get one thread to do o different things at the same time: show what is going on, and wait for a specific product of time before doing something else - and that isn't going to work.
So set up a Timer, and user that to kick off the second colour change instead of trying to stop the current thread, because of you stop the thread, you can't see any changes...
这篇关于如何在两行之间添加延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文