using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Caching;
using System.Web.Services;

/// <summary>
/// CheckBeat 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
public class CheckBeat : System.Web.Services.WebService {

public CheckBeat () {

//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}

private static readonly string timeSession = "timebeat";

[WebMethod]
public string Heartbeat()
{
DateTime now = DateTime.Now;
HttpRuntime.Cache.Remove(timeSession);
HttpRuntime.Cache.Add(timeSession, now, null, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
Thread t = new Thread(new ParameterizedThreadStart(CheckBeats));
t.Start(now);
return "一次心跳完成,记录缓存值:" + now;
}

private void CheckBeats(object time)
{
DateTime now = (DateTime)time;
int times = 1;
for (int i = 1; i <= 10; i++)
{
Thread.Sleep(3000);
object obtime = HttpRuntime.Cache.Get(timeSession);
if (obtime != null)
{
DateTime sessionTime = (DateTime)obtime;
if (sessionTime > now) //心跳正常
{
break;
}
}
times++;
}
if (times > 10) //心跳终止
{
reStart();
//System.Diagnostics.Process.Start(@"D:\TWX\Debug\NewTest.exe");
}
}

private void reStart()
{
string appName = "NewTest";
string appPath = @"D:\TWX\Debug\NewTest.exe";

//send mobile message
try
{
Process[] myPro = Process.GetProcessesByName(appName);
myPro[0].Kill(); //删除进程
}
catch (Exception)
{

}
}

}

最新文章

  1. Android基础学习第二篇—Activity
  2. 8.mvc core上传文件
  3. 股市非常态,CCI指标买卖点实例图解
  4. 如何搭建maya plugin develop environment on MAC OS X
  5. 使用hibernate annotation 为非空列加上默认值
  6. http协议的总结说明
  7. [转]详解AppDelegate/UIApplication
  8. SQL注入漏洞和SQL调优SQL注入漏洞和SQL调优
  9. Jmeter接口测试使用beanshell断言json返回
  10. Caffe + Ubuntu 15.04 + CUDA 7.0 安装以及配置
  11. SpringSecurity身份验证基础入门
  12. 无法解析依赖项。“Microsoft.Net.Http 2.2.29”与 &#39;Microsoft.Net.Http.zh-Hans
  13. 【GMT43智能液晶模块】例程十二:SDIO实验——读取SD卡信息
  14. win10专业版密钥 亲测可用 不断更新
  15. webpack配置接口路径
  16. gitlab修改默认端口
  17. 下载YouTube视频的方法
  18. Eclipse配置C++环境
  19. Qt监控Arduino开关状态(读取串口数据)
  20. 去掉每行最后n个字符

热门文章

  1. access&#160;join形式删除数据
  2. 如何让thrift0.9.2 在macos上面编译通过?
  3. JavaWeb-HttpServletResponse对象一
  4. java中的静态分派和动态分派
  5. TensorFlow学习笔记(一)--windows系统安装配置
  6. gcc __attribute__
  7. python16_day22【cmdb注释】
  8. Discuz! 论坛
  9. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs
  10. 【android】 如何把gif图片下载到本地