小笔记:Timer定时间隔时间操作,后面有时间再补充和完善:

public class TimingSvc
{
/// <summary>
/// 定时器,执行定时任务
/// </summary>
private static Timer m_Timer;
static ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim();
private static int FlushTimeOut = 5000;
private TimingSvc()
{
//初始化操作
TimeSpan timeSpan = new TimeSpan();
DateTime nextTime = DateTime.Now.AddMilliseconds();
timeSpan = nextTime.Subtract(DateTime.Now);
m_Timer = new Timer(new TimerCallback(OnTimedEvent), null, (long)timeSpan.TotalMilliseconds, Timeout.Infinite);
} public void Close()
{
m_log.LogEvent("定时任务停止.");
m_Timer.Dispose();
} /// <summary>
/// 定时任务的执行
/// </summary>
protected void OnTimedEvent(object state)
{
//LogEvent("********开始执行定时任务********");
//开始执行,无限等待
m_Timer.Change(Timeout.Infinite, Timeout.Infinite); //执行任务逻辑,刷新数据
//TODO //下次间隔20s执行
DateTime nextTime = DateTime.Now.AddMilliseconds();
TimeSpan timeSpan = nextTime.Subtract(DateTime.Now);
m_Timer.Change((long)timeSpan.TotalMilliseconds, Timeout.Infinite);
return;
} public void DoOperation()
{
//写入加锁
if (rwLock.TryEnterWriteLock(FlushTimeOut))
{
try
{
//TODO BLL
}
catch (Exception ex)
{
LogError("赋值异常:" + ex.Message);
}
finally
{
rwLock.ExitWriteLock();
}
}
return;
}
}

待完善。。。。。。

小笔记:Timer定时间隔时间操作的更多相关文章

  1. Python3.x:简单时间调度Timer(间隔时间执行)

    Python3.x:简单时间调度Timer(间隔时间执行) threading模块中的Timer能够帮助实现定时任务,而且是非阻塞的: 代码: import threading import time ...

  2. python3笔记二十一:时间操作datetime和calendar

    一:学习内容 datetime calendar 二:datetime 1.模块说明:可以理解为datetime基于time进行了封装,提供了各种使用的函数,datetime模块的接口更直接,更容易调 ...

  3. python3笔记二十:时间操作time

    一:学习内容 time时间戳 time元组 time字符串 time时间转换图解 二:time 需要引入:import time 1.概念 UTC(世界协调时间):格林尼治天文时间,世界标准时间,在中 ...

  4. [Xcode 实际操作]八、网络与多线程-(20)时间控件Timer定时功能

    目录:[Swift]Xcode实际操作 本文将演示时间控件Timer定时功能的使用. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit cl ...

  5. Java学习笔记 -- Java定时调度工具Timer类

    1 关于 (时间宝贵的小姐姐请跳过) 本教程是基于Java定时任务调度工具详解之Timer篇的学习笔记. 什么是定时任务调度 基于给定的时间点,给定的时间间隔或者给定的执行次数自动执行的任务. 在Ja ...

  6. Python笔记:threading(多线程操作)

    Python的线程操作在旧版本中使用的是thread模块,在Python27和Python3中引入了threading模块,同时thread模块在Python3中改名为_thread模块,thread ...

  7. c# 定时启动一个操作、任务

    // 定时启动一个操作.任务 using System; using System.Collections.Generic; using System.Collections.ObjectModel; ...

  8. Mongodb Manual阅读笔记:CH2 Mongodb CRUD 操作

    2 Mongodb CRUD 操作 Mongodb Manual阅读笔记:CH2 Mongodb CRUD 操作Mongodb Manual阅读笔记:CH3 数据模型(Data Models)Mong ...

  9. JS 学习笔记--6---日期和时间

    在日期和时间这一块的学习中发现,其实和其他大部分的高级语言中时间和日期的操作差不多,没什么特别的,但是要注意的就是 ECMAScript中规定的一些方法在各大浏览器中的实现方式是不一样的,也就是说存在 ...

随机推荐

  1. HDU 4763 Theme Section

    题目: It's time for music! A lot of popular musicians are invited to join us in the music festival. Ea ...

  2. 【分享】一个集成tracert和ping的网络监测工具

    最近接到一个需求,需求背景是这样的:目前Windows平台下本身都有tracert和ping的实现,而且可以直接在cmd下使用. 需求中有两个要求: 1. Windows平台中的tracert执行速度 ...

  3. 关于userInteractionEnabled的属性的理解

    userInteractionEnabled A Boolean value that determines whether user events are ignored and removed f ...

  4. UITableViewCell滑动删除及移动

    实现Cell的滑动删除, 需要实现UITableView的代理UITableViewDelegate中如下方法: //先要设Cell可编辑 - (BOOL)tableView:(UITableView ...

  5. 为什么alertView弹出后button会消失的问题

    按option后会有提示:Do not use the label object to set the text color or the shadow color. Instead, use the ...

  6. C# WinForm程序退出的方法比较

    1.this.Close();   只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退出: 2.Application.Exit();  强制所有消息中 ...

  7. JavaSE-反射-获取类或者对象的四种方法

    1.使用Class类的静态方法Class.forName("xxxx"); 新建一个要想要获取的类 package org.burning.sport.javase.classlo ...

  8. arduino扩展IO与M74HC595B芯片的使用,挪车电话提示牌的设计

    2018-01-0915:39:24 视频连接 首先arduino中shiftOUT()函数的定义与说明! shiftOut()描述将一个数据的一个字节一位一位的移出.从最高有效位(最左边)或最低有效 ...

  9. pandas读取excel中指定数据的行数

    shuju = pd.read_excel(filename) loandata = pd.DataFrame(shuju) ncol = (len(loandata.keys())) data = ...

  10. Windows核心编程&作业

    1. 作业内核对象 允许将进程组合在一起并创建一个"沙箱"来限制进程能够做什么.我们可以将作业内核对象想象成一个进程容器(即使只有一个进程也具有相当的重要性) 限制包括可以分配的最 ...