我想每5分钟调用一次方法。我怎样才能做到这一点?
public class Program { static void Main(string[] args) { Console.WriteLine("*** calling MyMethod *** "); Console.ReadLine(); } private MyMethod() { Console.WriteLine("*** Method is executed at {0} ***", DateTime.Now); Console.ReadLine(); } }
var startTimeSpan = TimeSpan.Zero; var periodTimeSpan = TimeSpan.FromMinutes(5); var timer = new System.Threading.Timer((e) => { MyMethod(); }, null, startTimeSpan, periodTimeSpan);