Threading.Tasks 简单的使用
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 简单的使用的更多相关文章
- 一个简单 System.Threading.Tasks.Dataflow.TransformBlock 示例
直接贴代码了: using System; using System.Collections.Generic; using System.IO; using System.Threading.Task ...
- 一个简单 System.Threading.Tasks.Dataflow.BufferBlock 示例
直接贴代码了: using System; using System.Threading.Tasks; using System.Threading.Tasks.Dataflow; namespace ...
- 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”, 编写代码,生成一个 ...
- System.Threading.Tasks
前言: 我们之前介绍了两种构建多线程软件的编程技术(使用异步委托或通过System.Threading的成员).这两个可以在任何版本的.NET平台工作. 关于System.Threading 的介绍 ...
- .Net多线程编程—System.Threading.Tasks.Parallel
System.Threading.Tasks.Parallel类提供了Parallel.Invoke,Parallel.For,Parallel.ForEach这三个静态方法. 1 Parallel. ...
- Threading.Tasks.Task多线程 静态全局变量(字典) --只为了记录
--------------------------------------------------------------后台代码---------------------------------- ...
- using System.Threading.Tasks;
using System.Threading.Tasks; .Net并行库介绍——Task1
- 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. ...
- 转载 Net多线程编程—System.Threading.Tasks.Parallel
.Net多线程编程—System.Threading.Tasks.Parallel System.Threading.Tasks.Parallel类提供了Parallel.Invoke,Paral ...
随机推荐
- POJ 1012 Joseph
Joseph Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44650 Accepted: 16837 Descript ...
- 关于fork的一道经典面试题
这是一道面试题,问程序最终输出几个“-”: #include<stdio.h> #include<sys/types.h> #include<unistd.h> i ...
- webkit特有的css属性
内容参见:http://css-infos.net/properties/webkit 具体的定义网页里有详细说明.做有一些html5的应用的时候如果不能很好的适应手机,可以到这上面去找找方法-web ...
- WCF 遇到的问题
1.只有项目的net版本2.0以上的才可以引用到wcf的类库 2.HTTP 错误 404.17 - Not Found 映射问题 WCF服务建立好,提示这个错误,缺少映射问题,要将应用程序池和项 ...
- [Git] 快速签出与更新所有远程分支.md
git-fetch 命令从远程仓库复制 heads 和 tags 信息到本地,保存在临时文件 .git/FETCH_HEAD 中以备 git-merge 命令使用. 你可以使用 git fetch 命 ...
- ruby -- 问题解决(八)解决Paperclip::NotIdentifiedByImageMagickError
好吧!又见 Paperclip::NotIdentifiedByImageMagickError,之前遇过一次... 最近又遇到一次,解决了之后,忘了写博客,然后再次遇到的时候,有一种被车撞到的节奏. ...
- Zookeeper集群部署
一. 部署前的准备工作 保证各个主机之间能够正常通信,最好是在同一网段. 修改host文件,加入IP和主机名的映射.方法为修改/etc/hosts和etc/hostname文件,不同的Linux发行版 ...
- 将excel导入mysql(使用navicat)
excel: 注: 1.mysql里建立一张跟excel一样的表结构的表(包含id) 2.excel最好没有任何格式,只是纯值,不然会出现导入不了的错误 ----------------------- ...
- 转载---CSS3实现曲线阴影和翘边阴影
预备知识 DIV+CSS基础 圆角:border-radius 2D变换:transform:skew && rotate 伪类::before 和 :after 代码 HTML结构代 ...
- timestamp的两个属性:CURRENT_TIMESTAMP 和ON UPDATE CURRENT_TIMESTAMP
timestamp有两个属性,分别是CURRENT_TIMESTAMP 和ON UPDATE CURRENT_TIMESTAMP两种,使用情况分别如下: 1. CURRENT_TIMESTAMP 当要 ...