本文转自:http://blog.csdn.net/sharpnessdotnet/article/details/7637180

一定要使用System.Timers.Timer timer 而不是System.Windows.Forms.Timer,否则就悲剧了.
public partial class InvkGpsWinService : ServiceBase
    {
        System.Timers.Timer timer = new System.Timers.Timer();
        public InvkGpsWinService()
        {
            InitializeComponent();
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);           
            timer.Interval = ConfigHelper.ApplicationAutoRunTimeSpan;           
        }
        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            InvkGps.Library.BizLogic.BizLogicObject_TRUCK_DATA.Proxy.Run();
        }
        protected override void OnStart(string[] args)
        {
            // TODO: 在此处添加代码以启动服务。
            timer.Enabled = true;
            timer.Start();
           
        }
        protected override void OnStop()
        {
            // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
            timer.Enabled = false;
            timer.Stop();
        }
     
    }

.net Windows Service安装包制作

http://blog.csdn.net/sqqyq/article/details/50475437

[转]在windows service中使用timer的更多相关文章

  1. Windows Service中使用Threading.Timer需注意回收

    在Windows Service中使用Threading.Timer时需要注意回收池问题 Threading.Timer是基于线程池的,系统会对其进行垃圾回收. 当Threading.Timer定义在 ...

  2. 如何托管ASP.NET Core应用到Windows Service中

    (此文章同时发表在本人微信公众号"dotNET开发经验谈",欢迎右边二维码来关注.) 题记:正在构思一个中间件的设计,考虑是否既可以使用最新的技术,也可以兼顾传统的部署模式.所以有 ...

  3. C# windows服务:C#windows服务中的Timer控件的使用

    C# windows服务程序中的Timer控件的使用问题是如何解决的呢? 今天和同事一起研究了下C# windows服务程序中的Timer控件的使用的写法. 我们在建立一个C# windows服务程序 ...

  4. 宿主在Windows Service中的WCF(创建,安装,调用) (host到exe,非IIS)

    1. 创建WCF服务 在vs2010中创建WCF服务应用程序,会自动生成一个接口和一个实现类:(IService1和Service1) IService1接口如下:   using System.Ru ...

  5. NetCore Selfhost,IIShost,Windows Service Host详解(自宿主、宿主在IIS,宿主在Windows Service中)

    第一部分.自托管 一.依赖.Net Core环境 修改 project.json 文件内容,增加发布时需要包含文件的配置内容(NetCore2.0版本不需要任何设置,NetCore2.0开始彻底放弃p ...

  6. ASP.NET Core应用到Windows Service中

    托管到Windows Service中 众所周知,ASP.NET Core采用了和传统ASP.NET不同的托管和HTTP处理方式,即把服务器和托管环境完全解耦. ASP.NET Core内置了两个HT ...

  7. .NET 6学习笔记(3)——在Windows Service中托管ASP.NET Core并指定端口

    在上一篇<.NET 6学习笔记(2)--通过Worker Service创建Windows Service>中,我们讨论了.NET Core 3.1或更新版本如何创建Windows Ser ...

  8. [转]Win7、Windows Server 2008下无法在Windows Service中打开一个已经存在的Excel 2007文件问题的解决方案

    昨天,组里一个小朋友告诉我,他写的报表生成服务中无法打开一个已经存在的Excel 2007文件,他的开发环境是Win7.Visual Studio .Net 2008(Windows Server 2 ...

  9. C# Windows Service中执行死循环轮询

    用C#编写Windows Service时,执行轮询一般有两种方式,一种是用Timer,System.Timers或者是System.Thread下的,这种执行是按时间循环执行,缺点是也许上个执行还没 ...

随机推荐

  1. 描述一下 cookies,sessionStorage 和 localStorage 的区别?

    sessionStorage 和 localStorage 是HTML5 Web Storage API 提供的,可以方便的在web请求之间保存数据.有了本地数据,就可以避免数据在浏览器和服务器间不必 ...

  2. Yaoge’s maximum profit HDU - 5052

    Yaoge’s maximum profit Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  3. Linux基础实验(二)

    一)基础实验: 1. 新建文件a.txt,并用权限模式.权限值两种方式修改权限为rwxrwx--x     新建文件:touch a.txt    权限模式:chmod ug=rwx o=x a.tx ...

  4. “全栈2019”Java异常第十八章:Exception详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java异 ...

  5. java中数组的插入

    package com.hxzy.demo; import java.util.Arrays;import java.util.Scanner; public class Demo1 { public ...

  6. 虚拟机搭建ftp环境

    引用http://www.cnblogs.com/xiangxiaodong/archive/2013/12/23/3487028.html,学习. 本人是在windows8系统下,Oracle VM ...

  7. iOS开发debug跟release版本NSLog屏蔽方法

    简单介绍以下几个宏: 1) __VA_ARGS__ 是一个可变参数的宏,这个可变参数的宏是新的C99规范中新增的,目前似乎只有gcc支持(VC6.0的编译器不支持).宏前面加上##的作用在于,当可变参 ...

  8. day4. python学习之字典

    字典和列表是最常用的数据类型,字典是一种key-value的数据类型,用{ }表示 1.字典的特性:无序的,没有下标 2.字典的使用:增删改查 info = { '20181101':"zh ...

  9. [原创] PHP 使用Redis实现锁

    目录 锁实现的注意点 加锁 connect 与 pconnect 解锁 Redis 中使用 Lua 脚本的注意点 Redis集群分布式锁 RedLock 算法 锁实现的注意点 互斥: 任意时刻, 只能 ...

  10. You need to use a Theme.AppCompat theme (or descendant) with this activity问题

    You need to use a Theme.AppCompat theme (or descendant) with this activity问题 https://blog.csdn.net/j ...