博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 定时器运用
阅读量:7230 次
发布时间:2019-06-29

本文共 1070 字,大约阅读时间需要 3 分钟。

在晚上12点执行任务

 

 

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;

namespace WindowsService2

{
public partial class Service1 : ServiceBase
{
System.Timers.Timer timer1; //计时器
WindowTaske w = new WindowTaske();
public Service1()
{
InitializeComponent();
}

protected override void OnStart(string[] args)

{
timer1 = new System.Timers.Timer();

timer1.Interval = 3000; //设置计时器事件间隔执行时间

timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Elapsed);

timer1.Enabled = true;

if (!EventLog.SourceExists("OnStart222"))

{
EventLog.CreateEventSource("OnStart222", "jason");
}

EventLog.WriteEntry("OnStart222", "开始任务了");

}

protected override void OnStop()

{
this.timer1.Enabled = false;
EventLog.WriteEntry("OnStart222", "任务结束");
}

private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)

{
if (e.SignalTime.Hour == 0 && e.SignalTime.Minute == 0 && e.SignalTime.Second == 0)//晚上12点发送邮件
{
//发送邮件方法
}
}

}
}

转载地址:http://ebdfm.baihongyu.com/

你可能感兴趣的文章
ionic $ionicSlideBoxDelegate 滑动框事件
查看>>
点击文字,把input type="radio"也选中
查看>>
第一章 Java多线程技能
查看>>
Java 集合系列-第八篇-Map架构
查看>>
springmvc 3.2 @MatrixVariable bug 2
查看>>
React-Native PanResponder手势识别器
查看>>
IOS11 光标错位问题
查看>>
如何设计用户登录
查看>>
linux安装mysql5.7.19
查看>>
Zookeeper+ActiveMQ 集群实现
查看>>
加权有向图问题2----多源最短路径问题(Floyd算法)和关键路径算法
查看>>
logback logback.xml常用配置详解(三) <filter>
查看>>
KgMall B2B/B2B2c/C2C版店铺商号初始化
查看>>
Linux内核的ioctl函数学习
查看>>
Liunx Shell入门
查看>>
Thread的中断
查看>>
linux --- 内存管理
查看>>
PostgreSQL
查看>>
CPU 超线程、多核
查看>>
用ASCII码显示string.xml中的特殊字符
查看>>