Windows Service(服务)  是运行在后台的进程

1、VS建立 Windows 服务(.NET Framework)

2、添加Timer

双击Service1.cs可以拖控件(System.Windows.Forms.Timer)这儿注意命名空间哦,

双击 trmer1 生成事件,修改事件方法如下:

App.config:

<appSettings>
<add key="TimerExecTime" value="0001-01-01 10:07:00"/>
</appSettings>

Service1.cs

private void timer1_Tick(object sender, EventArgs e)
{
_logger.Info("timer1_Tick");
DateTime execTime = DateTime.Parse(ConfigurationManager.AppSettings["TimerExecTime"]);
_logger.Info("timer1_Tick" + execTime.Year);
if (execTime.Year == )
{
_logger.Info("yea"+ execTime.Hour + "Minute"+ execTime.Minute);
DateTime curTime = DateTime.Now;
if (execTime.Hour == curTime.Hour && execTime.Minute == curTime.Minute)
{
//每天几小时几分执行代码
}
}
}

进入Service1.Designer.cs  修改如下:

        #region 组件设计器生成的代码

        /// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
//this.timer1 = new System.Timers.Timer(this.components);
this.timer1 = new System.Timers.Timer();
//
// timer1
//
this.timer1.Interval = ;
//this.timer1.Tick += new System.EventHandler(this.timer1_Tick); this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Tick);
this.timer1.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
this.timer1.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
//
// Service1
//
this.ServiceName = "Service1"; } #endregion public System.Timers.Timer timer1;

3、调试方法引用:

https://www.cnblogs.com/xiebin1986/archive/2011/12/15/2288893.html

4、安装与卸载

在Service1.cs 右键=》添加安装程序 ,生成 ProjectInstaller.cs

serviceInstaller1 设置如下图:

serviceProcessInstaller1设置如下图:

生成时

Install.bat

%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\installutil.exe 路径Release  Service.exe
Net Start 服务名
sc config 服务名 start= auto

Uninstall.bat

%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\installutil.exe /u  路径Release  Service.exe

.Net Windows Service(服务) 调试安装及System.Timers.Timer 使用的更多相关文章

  1. C# Windows Service服务的创建和调试

    前言 关于Windows服务创建和调试的文章在网络上的很多文章里面都有,直接拿过来贴在这里也不过仅仅是个记录,不会让人加深印象.所以本着能够更深刻了解服务项目的创建和调试过程及方法的目的,有了这篇记录 ...

  2. windows Service 之调试过程(附加到进程里调试,而且启动时间不能超过30秒)

    最近第一次用C#写了一个windows service ,其实实现的内容比较简单.就是启动remoting 连接,但是调试相对初次写windws service 的我来说,比较烦.没有经验,而且没办法 ...

  3. C#Windows Service服务程序的安装/卸载、启动/停止 桌面客户端管理程序设计

    C#Windows Service服务程序的安装/卸载.启动/停止 桌面客户端管理程序设计 关于Windows Service程序的安装与卸载如果每次使用命令行操作,那简直要奔溃了,太麻烦而且还容易出 ...

  4. 震惊!Windows Service服务和定时任务框架quartz之间原来是这种关系……

    过场CG:   接到公司领导的文件指示,“小熊”需要在6月底去海外执行一个行动代号为[定时任务]的营救计划,这个计划关系到公司某个项目的生死(数据安全漏洞),作战部拟定两个作战方案: 方案一:使用务定 ...

  5. quartz.net结合Topshelf实现windows service服务托管的作业调度框架

    topshelf可以很简单方便的实现windows service服务,详见我的一篇博客的介绍 http://www.cnblogs.com/xiaopotian/articles/5428361.h ...

  6. Windows Service 服务搭配FluentScheduler实现定时任务调度

    Windows Service 服务 创建Windows Service 项目 创建一个Windows Service项目,并将项目名称改为 TaskWindowService 在解决方案资源管理器内 ...

  7. windows service 2008 R2 安装net4.6环境失败,windows service 2008 R2 升级sp1问题

    一.错误 1.因为我的程序是以vs2017开发的,在windows service 2008 R2  IIS部署项目文件报出错误,因此要安装net4.6的环境. 2.windows service 2 ...

  8. System.Windows.Forms.Timer、System.Timers.Timer、System.Threading.Timer的 区别和用法

    System.Windows.Forms.Timer执行的时候,如果你在过程中间加一个sleep整个的界面就死掉了,但是另外两个没有这个情况,System.Timers.Timer.System.Th ...

  9. 简述System.Windows.Forms.Timer 与System.Timers.Timer用法区别

    System.Windows.Forms.Timer 基于窗体应用程序 阻塞同步 单线程 timer中处理时间较长则导致定时误差极大. System.Timers.Timer 基于服务 非阻塞异步 多 ...

随机推荐

  1. 使用AOF持久化文件实现还原Redis数据库并得到RDB持久化文件

    目录 1 编写本文的初衷 2 具体实施 2.1 Redis持久化概念简介 2.2 获取指定Redis的AOF持久化文件 2.3 把Redis的持久化AOF文件转换为RDB文件 1 编写本文的初衷 因为 ...

  2. numpy 中的 broadcasting 理解

    broadcast 是 numpy 中 array 的一个重要操作. 首先,broadcast 只适用于加减. 然后,broadcast 执行的时候,如果两个 array 的 shape 不一样,会先 ...

  3. windows10多桌面创建 切换 和分屏

    windows键+Tab 可以创建和切换新的桌面 win+ctrl+左右箭头 可以切换桌面 Aero Snap是Win7时代增加的一项窗口排列功能,俗称“分屏”.一个最简单例子,就是当你把窗口拖至屏幕 ...

  4. (原)MobileNetV2

    转载请注明出处: https://www.cnblogs.com/darkknightzh/p/9410574.html 论文: MobileNetV2: Inverted Residuals and ...

  5. Variable used in lambda expression should be final or effectively final

    Lambda与匿名内部类在访问外部变量时,都不允许有修改变量的倾向,即若: final double a = 3.141592; double b = 3.141592; DoubleUnaryOpe ...

  6. Linux 系统实时监控的瑞士军刀 —— Glances

    Linux 系统实时监控的瑞士军刀 —— Glances 对于 RHEL/CentOS/Fedora 发行版 ## RHEL/CentOS 7 64-Bit ## # wget http://dl.f ...

  7. 【转】AlphaGo Zero 和强人工智能

    AlphaGo Zero 和强人工智能 前段时间比较热门的是 AlphaGo(阿法狗)的升级版:AlphaGo Zero(阿法狗零).跟阿法狗不同,阿法狗零不依赖于任何人类对弈记录,完全从围棋的规则出 ...

  8. Django的AbstractUser的几大步骤

    - 导入 AbstractUser from django.contrib.auth.models import AbstractUser - 往其中添加列,即可在Django的基础上添加我们所需要的 ...

  9. Spring Boot 2.0 热部署指南

    Spring Boot 2.0 支持热部署,实现方法很简单 Spring Boot 2.0 有几种热重载的选项. 推荐的方法是使用spring-boot-devtools 因为它提供了额外的开发时间功 ...

  10. [k8s]zookeeper集群在k8s的搭建(statefulset模式)-pod的调度

    之前一直docker-compose跑zk集群,现在把它挪到k8s集群里. docker-compose跑zk集群 zk集群in k8s部署 参考: https://github.com/kubern ...