Skip to content

Instantly share code, notes, and snippets.

@mrcnkoba
Created July 11, 2014 20:11
Show Gist options
  • Save mrcnkoba/7007393ed3e5d7b0b74d to your computer and use it in GitHub Desktop.
Save mrcnkoba/7007393ed3e5d7b0b74d to your computer and use it in GitHub Desktop.
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