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. Hashing Trick

    本博客已经迁往http://www.kemaswill.com/, 博客园这边也会继续更新, 欢迎关注~ 在机器学习领域, kernel trick是一种非常有效的比较两个样本(对象)的方法. 给定两 ...

  2. ios 数组排序

    第一种:利用数组的sortedArrayUsingComparator调用 NSComparator  示例: obj1和obj2指的是数组中的对象 //1.数组中存放的是字符 NSComparato ...

  3. Using the Cordova Camera API

    使用ionic开发一款android或ios应用,估计少不了使用到Camera API,这里记录下使用过程. 创建空的ionic应用 ionic start myTabs tabs 通过cd demo ...

  4. react-native SyntaxError xxxxx/xx.js:Unexpected token (23:24)

    在运行react-native项目时提示 SyntaxError xxxxx/xx.js:Unexpected token (23:24) 我这边的问题原因:jsx语法错误,解决办法就是认真排查代码然 ...

  5. Application MyTest has not been registered. This is either due to a require() error during initialization or failure to call AppRegistry.registerComponent.

    运行react-native项目时报错. 说明一下:项目本来是好的,再次运行就报错了 解决解决办法倒是有,不过具体什么原因不知道.希望有知道具体原因的童鞋能够补充一下 第一种情况:真的是注册的时候写错 ...

  6. ruby self.included用法

    ===Module#included 当一个模块混入到类时,如果该模块的included方法已经定义,那么该方法被调用.该方法的唯一参数就是接受混含的类的名字. module M def self.i ...

  7. MyBatis知多少(16)MyBatis映射

    之前我们详细地讨论了MyBatis背后的设计理念以及iBATIS框架是如何产生的.也说明了MyBatis是一个混合型解决方案,它从处理关系数据库的其他不同方法那里借鉴了许多思想.那么MyBatis到底 ...

  8. C# 解析百度天气数据,Rss解析百度新闻以及根据IP获取所在城市

    百度天气 接口地址:http://api.map.baidu.com/telematics/v3/weather?location=上海&output=json&ak=hXWAgbsC ...

  9. NPM使用详解(上)

    1.NPM是什么? NPM是JavaScript的包管理工具,在安装NodeJS(什么?你不知道node?来,我们合计合计:https://nodejs.org/)的时候,会自动安装上npm. 要查看 ...

  10. CentOS下安装JDK7 转载

    转载地址:http://www.cnblogs.com/rilley/archive/2012/02/02/2335395.html CentOS下安装JDK7 下载地址:http://www.ora ...