Exemplo n.º 1
0
        void timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                //Thread.Sleep(10000);

                string webAppUrl = ConfigurationManager.AppSettings["WebAppUrl"];
                if (!string.IsNullOrWhiteSpace(webAppUrl))
                {
                    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(webAppUrl);
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.KeepAlive   = false;
                    request.Method      = "get";

                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    Stream       stream = response.GetResponseStream();
                    StreamReader sr     = new StreamReader(stream);

                    sr.Close();
                    stream.Close();
                    response.Close();
                }

                TimeSpan ts           = DateTime.Now - DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 05:00:00");
                int      totalSeconds = (int)ts.TotalSeconds * 1000;
                if (totalSeconds < timer2.Interval / 2 && totalSeconds > -timer2.Interval / 2)
                {
                    string appPath = ConfigurationManager.AppSettings["AppPath"];
                    if (!string.IsNullOrWhiteSpace(appPath))
                    {
                        string    fileName = Path.GetFileNameWithoutExtension(appPath);
                        Process[] proc     = Process.GetProcessesByName(fileName);
                        if (proc.Length > 0)
                        {
                            lock (lockObj)
                            {
                                ProcessAsUser.Launch("taskkill /f /t /im " + Path.GetFileName(appPath));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //log 邮件
            }
        }
Exemplo n.º 2
0
 void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     try
     {
         string appPath = ConfigurationManager.AppSettings["AppPath"];
         if (!string.IsNullOrWhiteSpace(appPath))
         {
             string    fileName = Path.GetFileNameWithoutExtension(appPath);
             Process[] proc     = Process.GetProcessesByName(fileName);
             if (proc.Length == 0)
             {
                 lock (lockObj)
                 {
                     ProcessAsUser.Launch(appPath);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         //log 邮件
     }
 }