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)
{

}
}

}

.net 下的 HttpRuntime.Cache 应用的更多相关文章

  1. 缓存 HttpContext.Current.Cache和HttpRuntime.Cache的区别

    先看MSDN上的解释: HttpContext.Current.Cache:为当前 HTTP 请求获取Cache对象. HttpRuntime.Cache:获取当前应用程序的Cache.  我们再用. ...

  2. HttpContext.Current.Cache 和HttpRuntime.Cache的区别

    先看MSDN上的解释:      HttpContext.Current.Cache:为当前 HTTP 请求获取Cache对象.      HttpRuntime.Cache:获取当前应用程序的Cac ...

  3. ASP.NET HttpRuntime.Cache缓存类使用总结

    1.高性能文件缓存key-value存储—Redis 2.高性能文件缓存key-value存储—Memcached 备注:三篇博文结合阅读,简单理解并且使用,如果想深入学习,请多参考文章中给出的博文地 ...

  4. HttpContext.Current.Cache 和 HttpRuntime.Cache 区别

    原文地址:http://blog.csdn.net/avon520/article/details/4872704 .NET中Cache有两种调用方式:HttpContext.Current.Cach ...

  5. HttpRuntime.Cache .Net自带的缓存类

    .Net自带的缓存有两个,一个是Asp.Net的缓存 HttpContext.Cache,一个是.Net应用程序级别的缓存,HttpRuntime.Cache. MSDN上有解释说: HttpCont ...

  6. HttpContext.Current.Cache 和 HttpRuntime.Cache

    HttpRuntime.Cache:用于winfrom 和 web HttpContext.Current.Cache 用于web .NET中Cache有两种调用方式:HttpContext.Curr ...

  7. ASP.NET 中HttpRuntime.Cache缓存数据

    最近在开始一个微信开发,发现微信的Access_Token获取每天次数是有限的,然后想到缓存,正好看到微信教程里面推荐HttpRuntime.Cache缓存就顺便看了下. 写了(Copy)了一个辅助类 ...

  8. Cache及(HttpRuntime.Cache与HttpContext.Current.Cache)

    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/avon520/archive/2009/11/25/4872704.aspx .NET中Cache有两种调用方式:Ht ...

  9. HttpContext.Current.Cache和HttpRuntime.Cache的区别,以及System.Runtime.Caching

    先看MSDN上的解释:      HttpContext.Current.Cache:为当前 HTTP 请求获取Cache对象.      HttpRuntime.Cache:获取当前应用程序的Cac ...

随机推荐

  1. 转!mysql 命令行下 通过DELIMITER临时改变语句分隔符 执行存储过程

    mysql 在 Navicat 界面工具 执行存储过程ok,但是在命令行下执行失败. 原因在于,默认的MySQL语句分隔符为' ; ',在输入' ; '的时候,“以为”语句已经结束了,但实际上语句还没 ...

  2. python在处理CSV文件时,字符串和列表写入的区别

    概述 Python在处理CSV文件时,如果writerow的对象是<type 'unicode'>字符串时,写入到CSV文件时将会出现一个字符占一个单元格的情况: 但是将字符串转换为列表类 ...

  3. springMvc异常之 For input string: "show"

    异常提示: For input string: "show" 异常原因: 使用@PathVariable方式获取值,返回类型为String return "redirec ...

  4. Nginx+tomcat配置负载均衡集群

    操作系统版本:Centos 6.4 Nginx版本:nginx-1.3.15.tar.gz wget http://nginx.org/download/nginx-1.5.9.tar.gz JDK版 ...

  5. GlusterFS部署

    一.GlusterFS简介 PB级容量.高可用.读写性能.基于文件系统级别共享.分布式.无metadata(元数据)的存储方式. GlusterFS(GNU ClusterFile System)是一 ...

  6. Wilcoxon符号秩+秩和检验学习[转载]

    参数检验就是已知数据的精确分布模型,根据数据来求出模型中的未知参数:而非参数检验就是无需对样本总体分布(比如满足正态分布)做出假设. 1.符号检验 转自:https://baike.baidu.com ...

  7. 开启mysql的远程访问

    1.登陆mysql数据库 mysql -u root -p 查看user表 mysql> use mysql;Database changedmysql> select host,user ...

  8. (转)VC串口小程序(用SerialPort类)

    ××××××××××××××××××××××××××××××××××××××××××××××××××××× 在MFC里面实现串口通讯有很多方式: 方案一:使用微软公司提供的 串口类,SerialPor ...

  9. windows安装oracle client 18c 和plsql工具

    安装须知: (1)安装平台选择.linux/windows (2)软件位数选择.32/64,如果你的plsql工具是32位,那么你就安装32位客户端,如果是64位,你就安装64位客户端. 安装过程: ...

  10. cocos2d: fullPathForFilename: No file found at /cc_2x2_white_image. Possible missing file.

    程序运行的时候输出这条信息cocos2d: fullPathForFilename: No file found at /cc_2x2_white_image. Possible missing fi ...