在简单的控制台C#应用程序命令之间暂停

问题描述:

有没有简单的如何如有命令之间延迟1秒?我只能想到一些大的周期。我知道了Thread.Sleep但它不是我所期待的 - 我想只用别的东西没有关系的线程。
感谢您的任何想法。

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

我的认为的你是像收益回报。

这可以让你有传控制权返回给调用代码,然后可以通过您的应用程序进行。该环节都有其使用的一个很好的例子。

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";
    }
}