using Lemon.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Timers;
using System.Web; namespace Lemon.Stats.Web.Service
{
public class SynchCacheDataService
{
/// <summary>
/// 定时器
/// </summary>
private static System.Timers.Timer TimerOne; public static void StartService()
{
TimerOne = new System.Timers.Timer();
TimerOne.Interval = ; //1分钟执行一次(毫秒单位)
TimerOne.Elapsed += new ElapsedEventHandler(TimeUpdateDataTimer_Elapsed);
TimerOne.Enabled = true;
} /// <summary>
/// 定时器执行事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void TimeUpdateDataTimer_Elapsed(object sender, ElapsedEventArgs e)
{
SynchCacheData();
} /// <summary>
/// 同步缓存数据事件
/// </summary>
/// <returns></returns>
public static Task<int> SynchCacheData()
{
return Task.Run(() =>
{
return SyncHelper.SyncCacheData();
});
}
}
}

调用方式:

using Lemon.Stats.Web.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Security;
using System.Web.SessionState; namespace Lemon.Stats.Web
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
GlobalConfiguration.Configure(WebApiConfig.Register);
GlobalConfiguration.Configure(FormatConfig.Register); //启动同步缓存数据
SynchCacheDataService.StartService();
} protected void Session_Start(object sender, EventArgs e)
{ } protected void Application_BeginRequest(object sender, EventArgs e)
{ } protected void Application_AuthenticateRequest(object sender, EventArgs e)
{ } protected void Application_Error(object sender, EventArgs e)
{ } protected void Session_End(object sender, EventArgs e)
{ } protected void Application_End(object sender, EventArgs e)
{ }
}
}

Threading.Tasks 简单的使用的更多相关文章

  1. 一个简单 System.Threading.Tasks.Dataflow.TransformBlock 示例

    直接贴代码了: using System; using System.Collections.Generic; using System.IO; using System.Threading.Task ...

  2. 一个简单 System.Threading.Tasks.Dataflow.BufferBlock 示例

    直接贴代码了: using System; using System.Threading.Tasks; using System.Threading.Tasks.Dataflow; namespace ...

  3. vs2013c#测试using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1_CXY { class Program { stati

    首先安装Unit Test Generator.方法为:工具->扩展和更新->联机->搜索“图标为装有蓝色液体的小试管.Unit Test Generator”, 编写代码,生成一个 ...

  4. System.Threading.Tasks

    前言: 我们之前介绍了两种构建多线程软件的编程技术(使用异步委托或通过System.Threading的成员).这两个可以在任何版本的.NET平台工作. 关于System.Threading 的介绍 ...

  5. .Net多线程编程—System.Threading.Tasks.Parallel

    System.Threading.Tasks.Parallel类提供了Parallel.Invoke,Parallel.For,Parallel.ForEach这三个静态方法. 1 Parallel. ...

  6. Threading.Tasks.Task多线程 静态全局变量(字典) --只为了记录

    --------------------------------------------------------------后台代码---------------------------------- ...

  7. using System.Threading.Tasks;

    using System.Threading.Tasks; .Net并行库介绍——Task1

  8. HttpClient exception:ExceptionType:System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System.IO.IOException: Unable to read data from the transport connection: Operation ca

    error msg: System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System. ...

  9. 转载 Net多线程编程—System.Threading.Tasks.Parallel

    .Net多线程编程—System.Threading.Tasks.Parallel   System.Threading.Tasks.Parallel类提供了Parallel.Invoke,Paral ...

随机推荐

  1. jQuery Raion, Select, CheckBox selector function

    Radio jQuery("input[type=checkbox][name='fbCqscsf.cqzdycqk']").not("[value=1]"). ...

  2. JS获取跨域的cookie实例

    如果说JS能实现跨域cookie,你可能觉得不太可能实现,不过事实上,这个还是可以搞定的,不过需要一定的条件才行的哦!具体方案如下: 一共需要3个文件,第一个文件为需要获取cookie的页面,在这个页 ...

  3. Android应用如何支持屏幕多尺寸多分辨率问题

    作为Android应用程序开发者都知道android是一个“碎片化”的世界.多种系统版本.多种尺寸.多种分辨率.多种机型,还有不同的厂商定制的不同ROM,你开发的应用会在不可预期的手机上报错.这给开发 ...

  4. php中关于js保存文件至本地的问题

    最近在搞一个livezilla的在线客服聊天的东东,客户界面要求添加一个下载聊天记录的功能.于是我就是翻看了下网上的各种关于”js保存文件至本地“的资料,发现只能在IE下通过execCommand实现 ...

  5. outlook无法创建保存附件解决

    用outlook2003收发邮件时,当打开或另存附件时提示“无法创建和保存文件” 解决 开始-运行,输入“regedit”打开注册表,打开以下键值“HKEY_CURRENT_USER\software ...

  6. bootstrap插件学习-bootstrap.carousel.js

    先看bootstrap.carousel.js的结构 var Carousel = function (element, options){} //构造器 Carousel.prototype = { ...

  7. 初用DataGrip,连接后看不到自己创建的数据库的问题

      1.首先,成功连接数据库服务 2.可以看到默认连接到名为"larins_qr_db"的数据库 3.这时,我想看其它的数据库怎么办? 4.OK,想要的出现了!

  8. HT图形组件设计之道(二)

    上一篇我们自定义CPU和内存的展示界面效果,这篇我们将继续采用HT完成一个新任务:实现一个能进行展开和合并切换动作的刀闸控件.对于电力SCADA和工业控制等领域的人机交互界面常需要预定义一堆的行业标准 ...

  9. 连续值的CART(分类回归树)原理和实现

    上一篇我们学习和实现了CART(分类回归树),不过主要是针对离散值的分类实现,下面我们来看下连续值的cart分类树如何实现 思考连续值和离散值的不同之处: 二分子树的时候不同:离散值需要求出最优的两个 ...

  10. 看看如何面试前端工程师:Github很重要

    从程序员的角度提出要去学习哪些知识,下面这篇文章从面试官的角度介绍到面试时可能会问到的一些问题.不过我想先给你们一个忠告,招聘是一件非常艰巨的任务,在45分钟内指出一名侯选人是否合适是你需要完成的任务 ...