Created
July 11, 2014 20:11
-
-
Save mrcnkoba/7007393ed3e5d7b0b74d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ITask | |
{ | |
void Execute(); | |
} | |
public class SimpleTask : ITask | |
{ | |
public void Execute() | |
{ | |
Console.WriteLine("X"); | |
} | |
} | |
public static void Schedule<T>(TimeSpan timespan) where T : ITask | |
{ | |
var x = Activator.CreateInstance<T>(); | |
Schedule(timespan, x.Execute); | |
} | |
private static void Schedule(TimeSpan timespan, Action task) | |
{ | |
Task.Run(async () => | |
{ | |
while (true) | |
{ | |
task(); | |
await Task.Delay(timespan); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment