views:

61

answers:

2

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

A: 

use System.Diagnostics Stopwatch class in a loop

jules
see http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx for reference and usage examples
jules
+2  A: 

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