控制台程序定时重启

调用

if (!System.Diagnostics.Debugger.IsAttached)
{
     int times = 24 * 3600;
     自动重启(times);
}



private static void 自动重启(int times)
{
     new System.Timers.Timer(times * 1000)
     {
         Enabled = true,
         AutoReset = true
     }.Elapsed += (s, y) =>
     {
         try
         {
             //udpServer.Close();
             log("定时重启");
             Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
             Application.Exit();
             Environment.Exit(0);
         }
         catch (Exception ex)
         {
             //udpServer.Close();
             Environment.Exit(0);
             Application.Exit();
         }
     };
}

posted @ 2024-08-20 21:06  网络来者  阅读(17)  评论(0)    收藏  举报