.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 ...
随机推荐
- Elasticsearch提示low disk watermark [85%] exceeded on [UTyrLH40Q9uIzHzX-yMFXg][Sonofelice][/Users/baidu/Documents/work/soft/data/nodes/0] free: 15.2gb[13.4%], replicas will not be assigned to this node
mac本地启动es之后发现运行一段时间一分钟就能打印好几条info日志: [--13T10::,][INFO ][o.e.c.r.a.DiskThresholdMonitor] [Sonofelice ...
- Python自省(反射)指南(转)
原文:http://www.cnblogs.com/huxi/archive/2011/01/02/1924317.html 在笔者看来,自省和反射是一回事,当然其实我并不十分确定一定以及肯定,所以如 ...
- IIS7.5 错误代码0x8007007e HTTP 错误 500.19
目录 问题案例 解决问题 参考资料 问题案例 今天在win2008+IIS7.5的环境中部署WCF服务后,一直出现无法打开的页面.具体错误信息如下: HTTP 错误 500.19 - Internal ...
- Android ListView工作原理完全解析(转自 郭霖老师博客)
原文地址:http://blog.csdn.net/guolin_blog/article/details/44996879 在Android所有常用的原生控件当中,用法最复杂的应该就是ListVie ...
- java中使用MD5对密码进行加密
import org.springframework.security.authentication.encoding.MessageDigestPasswordEncoder; import org ...
- python 随机分类
#encoding:utf-8import pandas as pdimport numpy as npfrom sklearn import datasets,linear_modelfrom sk ...
- HDU 1116 Play on Words(欧拉路径(回路))
http://acm.hdu.edu.cn/showproblem.php?pid=1116 题意:判断n个单词是否可以相连成一条链或一个环,两个单词可以相连的条件是 前一个单词的最后一个字母和后一个 ...
- 性能调优之MySQL篇一:MySQL性能计数器
计数器 计数器分析 Threads_connected 表示当前有多少个客户连接该mysql服务器,连接数是否过多,网络是否存在问题,它是动态变化的,当达到最大连接数时,数据库系统就不能提供更多的连接 ...
- JMS--消息头
一个消息对象分为三部分:消息头(Headers),属性(Properties)和消息体(Payload).对于StreamMessage和MapMessage,消息本身就有特定的结构,而对于TextM ...
- win32api win32gui win32con 窗口句柄 发送消息 常用方法
Pywin32是一个Python库,为python提供访问Windows API的扩展,提供了齐全的windows常量.接口.线程以及COM机制等等. 1.通过类名和标题查找窗口句柄,并获得窗口位置和 ...