how to continuously run a c# console application in background

前端 未结 4 394
醉梦人生
醉梦人生 2021-01-19 06:58

I would like to know how to run a c# program in background every five minute increments. The code below is not what I would like to run as a background process but would lik

4条回答
  •  隐瞒了意图╮
    2021-01-19 07:26

    How about using a System.Windows.Threading.DispatcherTimer?

    class Program
    {
        static void Main(string[] args)
        {
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = new TimeSpan(0, 5, 0); // sets it to 5 minutes
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }
    
        static void timer_Tick(object sender, EventArgs e)
        {
            // whatever you want to happen every 5 minutes
        }
    
    }
    

提交回复
热议问题