Is there any easy how to e.g. have 1 second delay between commands? I can only think of some large cycles. I know about thread.sleep but it is not what I am looking for - I would like to just use something else without relation to threads. Thanks for any idea
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I think that you are after something like yield return.
This allows you to have the pass control back to the calling code and then can carry on through your app. The link has a good example of its use.
using System;
using System.Collections;
class Test
{
static void Main(string[] args)
{
foreach (string x in Foo())
{
Console.WriteLine (x);
}
}
static IEnumerable Foo()
{
yield return "Hello";
yield return "there";
}
}
回答2:
use System.Diagnostics Stopwatch class in a loop