.net 下的 HttpRuntime.Cache 应用
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 应用的更多相关文章
- 缓存 HttpContext.Current.Cache和HttpRuntime.Cache的区别
先看MSDN上的解释: HttpContext.Current.Cache:为当前 HTTP 请求获取Cache对象. HttpRuntime.Cache:获取当前应用程序的Cache. 我们再用. ...
- HttpContext.Current.Cache 和HttpRuntime.Cache的区别
先看MSDN上的解释: HttpContext.Current.Cache:为当前 HTTP 请求获取Cache对象. HttpRuntime.Cache:获取当前应用程序的Cac ...
- ASP.NET HttpRuntime.Cache缓存类使用总结
1.高性能文件缓存key-value存储—Redis 2.高性能文件缓存key-value存储—Memcached 备注:三篇博文结合阅读,简单理解并且使用,如果想深入学习,请多参考文章中给出的博文地 ...
- HttpContext.Current.Cache 和 HttpRuntime.Cache 区别
原文地址:http://blog.csdn.net/avon520/article/details/4872704 .NET中Cache有两种调用方式:HttpContext.Current.Cach ...
- HttpRuntime.Cache .Net自带的缓存类
.Net自带的缓存有两个,一个是Asp.Net的缓存 HttpContext.Cache,一个是.Net应用程序级别的缓存,HttpRuntime.Cache. MSDN上有解释说: HttpCont ...
- HttpContext.Current.Cache 和 HttpRuntime.Cache
HttpRuntime.Cache:用于winfrom 和 web HttpContext.Current.Cache 用于web .NET中Cache有两种调用方式:HttpContext.Curr ...
- ASP.NET 中HttpRuntime.Cache缓存数据
最近在开始一个微信开发,发现微信的Access_Token获取每天次数是有限的,然后想到缓存,正好看到微信教程里面推荐HttpRuntime.Cache缓存就顺便看了下. 写了(Copy)了一个辅助类 ...
- Cache及(HttpRuntime.Cache与HttpContext.Current.Cache)
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/avon520/archive/2009/11/25/4872704.aspx .NET中Cache有两种调用方式:Ht ...
- HttpContext.Current.Cache和HttpRuntime.Cache的区别,以及System.Runtime.Caching
先看MSDN上的解释: HttpContext.Current.Cache:为当前 HTTP 请求获取Cache对象. HttpRuntime.Cache:获取当前应用程序的Cac ...
随机推荐
- 二叉树的先序、中序、后序和中序遍历——Java实现
package treeTraverse; /** * 定义一个树的结点类 */ public class Node { private int data; private Node leftChil ...
- 一.shell基础知识
参考网站:http://billie66.github.io/TLCL/book/chap08.html 1.字符“*”--展开 [me@linuxbox ~]$ echo * Desktop Doc ...
- Hadoop 入门教程
Hadoop 入门教程 https://blog.csdn.net/kkkloveyou/article/details/52348883
- 0603-Zuul构建API Gateway-通过Zuul上传文件,禁用Zuul的Filter
一.通过Zuul上传文件 参看地址:https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_ ...
- data.table进阶
上一篇讲述了data.table数据分析的一些基本方法,但是最近在用作数据分析时,发现在面对一些复杂场景时,这些基本的用法已经不能满足业务需求了,所以此篇就介绍data.table更进一步的用法. 先 ...
- POJ2653:Pick-up sticks(线段相交)
题目:http://poj.org/problem?id=2653 题意:题意很简单,就是在地上按顺序撒一对木棒,看最后有多少是被压住的,输出没有被压住的木棒的序号.(有点坑的就是没说清楚木棒怎么算压 ...
- R中的一些基础1106
1.R中NA,NaN,Inf代表什么? NA:缺失数据 NaN:无意义的数,比如sqrt(-2) Inf:正无穷大 -Inf:负无穷大 2.确定一个数值型vector的第一个最值(最大/最小)的下标: ...
- Linux常见错误之Could not get lock /var/lib/dpkg/lock - open
在Ubuntu系统上安装vim是遇到的问题: root@ubuntu:/# vim The program 'vim' can be found in the following packages: ...
- 百度NLP二面
实验室项目:1.实验室方向 2.用两分钟介绍自己的项目,创新点在哪里 个人项目: 1.自己实现的贝叶斯分类器,目的,怎么做的 2.怎么计算各个分类的先验.(因为我使用的训练预料是每个分类10篇 ...
- Linux系统——最小化安装
一.虚拟机进行Linux minimal 安装 网络连接:选择“自定义”——>VMnet8(NAT模式) #PC与NAT网络的虚拟机在不同网段,此时虚拟网卡作为网关建立通信 NAT模式可直接上I ...