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. Android界面布局基本属性

    在 android 中我们常用的布局方式有这么几种:1.LinearLayout ( 线性布局 ) :(里面只可以有一个控件,并且不能设计这个控件的位置,控件会放到左上角)              ...

  2. Ubuntu下的杀毒

      Ubuntu 11.04 杀毒软件ESET NOD32   Linux防病毒,并不代表没有病毒,只是数量过少.因技术精英发现漏洞后即时打补丁,病毒很少. 有兴趣的同学可以尝试下Ubuntu 11. ...

  3. S5PV210之Sate210-F DIY硬件,移植uboot,kernel,android 活动现在已经进入实施阶段吗,欢迎广大网友参与 !

    大家一起来diy 超低价四核的exynos4412或者Cortex A8S5pv210开源开发板 商业版Sate210已经完成了好久了.Sate4412 也已经出来.但是这两个接口非常全,主要是针对企 ...

  4. Quiz(贪心,快速幂乘)

    C. Quiz time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  5. zmq 学习笔记

    0. PUB/SUB, XPUB/XSUB filtering happens at publisher sides when sockets are using a connected protoc ...

  6. 【PRML读书笔记-Chapter1-Introduction】1.4 The Curse of Dimensionality

    维数灾难 给定如下分类问题: 其中x6和x7表示横轴和竖轴(即两个measurements),怎么分? 方法一(simple): 把整个图分成:16个格,当给定一个新的点的时候,就数他所在的格子中,哪 ...

  7. Safari下默认10位数字为电话号码,点击拨号

    <meta content="telephone=no" name="format-detection"/>

  8. Fireasy新版本发布

    1.5.40.42028  2015-2-4 ** Fireasy.Common 1.DynamicBuilder新增使用表达式SetCustomAttribute的重载方法 2.DateTimeEx ...

  9. Java知多少(110)数据库之插入记录

    插入数据表记录有3种方案 一.使用Statement对象 实现插入数据表记录的SQL语句的语法是: insert into 表名(字段名1,字段名2,……)value (字段值1,字段值2,……) 例 ...

  10. Teambition可用性测试记

    引言:最开始知道Teambition是几个月前,当时是想找一个团队协作工具.Teambition是候选之一,它的界面设计给我留下了印象.后来得知其背后年轻的创始团队还是让我有些小惊讶的.这次通过朋友介 ...