概述
服务器端
Request.ContentType = "text/html";
Response.ContentType = "text/html";
StreamReader reader = new StreamReader(Request.InputStream);
string test = reader.ReadToEnd();
Application.Lock();
if(test=="1010")
{
if( Session["StationName"]==null)
{
return;
}
string statioNname = Session["StationName"].ToString();
string stationId = Session["LockNo"].ToString();
StationState ss=new StationState {StationID = stationId, StationName = statioNname, online = "online"};
List<StationState> list = (List<StationState>)Application["BufferdStations"] ?? new List<StationState>();
if(list.Count<1)
{
list.Add(ss);
Application["BufferdStations"] = list;
}
foreach (StationState item in list)
{
if (item.StationName == statioNname&&item.online=="offline")
{
item.online = "online";
}
}
Application["BufferdStations"] = list;
}
Application.UnLock();
全局Global
System.Timers.Timer t = new System.Timers.Timer(1000 * Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["server_time"]));
protected void Application_Start(object sender, EventArgs e)
{
t.AutoReset = true;
t.Enabled = true;
//if (common.func.get_key("can_do") == "1")//也是在web.config中存取是否进行定时处理,其中common.func.get_key是自定义的获取设置的函数
t.Elapsed += Fun;
List<StationState> States =
new List<StationState>();
Application.Add("BufferdStations", States);
System.Diagnostics.Debug.WriteLine("Application_Start");
}
private void Fun(object sender, System.Timers.ElapsedEventArgs e)
{
try{
List<StationState> list = (List<StationState>)Application["BufferdStations"];
if(list==null)
{list=new List<StationState>();
}
if (list.Count<1)
{
return;
}
Application.Lock();
foreach (StationState item in list)
{
if (item.online != "online")
{
list.Remove(item);
}
}
Application["BufferdStations"] = list;
Application.UnLock();
List<StationState> listReSet = (List<StationState>) Application["BufferdStations"];
Application.Lock();
foreach (StationState item in listReSet)
{
item.online = "offline";
}
Application["BufferdStations"] = listReSet;
Application.UnLock();
}
catch(Exception se)
{
}
}
最后
以上就是内向火龙果为你收集整理的心跳设计的全部内容,希望文章能够帮你解决心跳设计所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复