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 ...
随机推荐
- [转]Android dex分包方案
转载自:https://m.oschina.net/blog/308583 当一个app的功能越来越复杂,代码量越来越多,也许有一天便会突然遇到下列现象: 1. 生成的apk在2.3以前的机器无法安装 ...
- HANA Studio打开系统显示Secure storage is locked
之前一直用着好好的,今天打开HANA Studio突然发现一个系统都不在了: 提示:‘Secure storage is locked’ 我点旁边的Unlocked没有任何反应,右键也没有功能了.如下 ...
- Intel HAXM安装错误处理:(TV-x) is not turned on
Android x86模拟器Intel Atom x86 System Image时提示Intel execute disable bit(xd) is not turned on 运行Elicpse ...
- 玩转PowerShell第一节——【后台任务处理】-技术&分享
概述 相信大家对后台任务处理不陌生,比如.Net的后台线程处理,Java的线程处理等等. 而当我们用PowerShell这个强大的工具时怎么样开启后台任务呢,以及怎样处理这些任务呢,本篇将会告诉你Po ...
- Asp.Net(C#)自动执行计划任务的程序实例分析
在业务复杂的应用程序中,有时候会要求一个或者多个任务在一定的时间或者一定的时间间隔内计划进行,比如定时备份或同步数据库,定时发送电子邮件等,我们称之为计划任务.实现计划任务的方法也有很多,可以采用SQ ...
- DDD:谈谈数据模型、领域模型、视图模型和命令模型
背景 一个类型可以充当多个角色,这个角色可以是显式的(实现了某个接口或基类),也可以是隐式的(承担的具体职责和上下文决定),本文就讨论四个角色:数据模型.领域模型.视图模型和命令模型. 四个角色 数据 ...
- AutoMapper用法一瞥
前段时候做个小项目用到了autoMapper(参考了NOP里的用法),感觉还行,用起来挺方便的.首先复杂的东西我就不说了,至于详细的教程我也就不写了,比较园子里有很多这样的文章,我就分享下,在项目中实 ...
- JS微信分享不好写?来封装一下
微信开发这块,作为开发工程师来说,一般是避免不了的,也好像发现一些朋友写微信分享都是在每个页面一大把一大把的代码. 代码冗余,即便是复制过来再改也很麻烦. 之前自己封装了一下js,今天来分享一下,希望 ...
- sql server 查找包含字符串的对象
sql server 查找包含字符串的对象 SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS object_name, o.type, o.type_ ...
- 在Asp.Net MVC中使用ModelBinding构造Array、List、Collection以及Dictionary
在asp.net mvc中,我们可以在html表单中使用特定的格式传递参数,从而通过model binder构造一些集合类型. 第一种方式 public ActionResult Infancy(Pe ...