调用方法上每隔x分钟 [英] calling method on every x minutes

查看:116
本文介绍了调用方法上每隔x分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要呼吁每5分钟的一些方法,我该怎么做呢?

 公共类节目
{
   静态无效的主要(字串[] args)
   {
      Console.WriteLine(***调用的MyMethod ***);
      到Console.ReadLine();
   }   私人的MyMethod()
   {
     Console.WriteLine(,DateTime.Now***方法是在{0}执行***);
     到Console.ReadLine();
   }
}


解决方案

  VAR定时器=新System.Threading.Timer((E)=>
{
    的MyMethod();
},NULL,0,TimeSpan.FromMinutes(5).TotalMilliseconds);

I want to call some method on every 5 minutes, how can I do this?

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 timer = new System.Threading.Timer((e) =>
{
    MyMethod();   
}, null, 0, TimeSpan.FromMinutes(5).TotalMilliseconds);

这篇关于调用方法上每隔x分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆