本文转自: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. WPF带小箭头的按钮

    XAML代码: <ControlTemplate x:Key="btnTpl" TargetType="RadioButton"> <Stac ...

  2. Android ImageView,ImageButton 与 Button

    1. ImageButton 继承自 ImageView.两者具备甚小,因为 ImageView 同样可以点击相应,同样有点击的阴影效果.实际上他们的区别在于默认 style.比如同样放一个背景和一个 ...

  3. iOS 错误 undefined symbols for architecture i386

    undefined symbols for architecture i386 这个错误困扰了我几个小时. 网上很多问这个问题的,回答基本上都是说在 target 里面去的 armv64 什么什么的. ...

  4. django系列6--Ajax01 特点, 基本格式, 向前端发送数据

    一.Ajax了解 AJAX(Asynchronous Javascript And XML)优点是在不重新加载整个页面的情况下,可以与服务器交换数据并更新部分网页内容 优点: 1.ajax使用Java ...

  5. windows10 pip install MySQL-python mysqlclient

    https://dev.mysql.com/downloads/connector/python/ 到上述地址下载对应系统的驱动程序安装即可. 安装mysqlclient方法如下: https://w ...

  6. UI1

    计算机工程系     目 录   实验一 Photoshop基本界面熟悉 3 实验二 PhotoShop常用工具的使用 4 实验三 图象和图层的处理 7 实验四 各种滤镜方式的处理 13 实验五 Ph ...

  7. 【App性能分析】:tracelog分析法

    tracelog可以记录每个OpenGL函数调用的消耗时间,所以很多时候用来作performance分析.目前只支持安卓4.1以上的版本设备 1,目前Android Device Monitor最新的 ...

  8. 04-树6 Complete Binary Search Tree (30 分)

    A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...

  9. Mac无法将自定义图标添加到Launchpad的替代方案(桌面双击Shell运行)

    截止在几天之前的Mac OS版本都无法实现将自定义图标添加到Launchpad.我使用的是10.12. 替代的思路就是在桌面新建一个Shell文件,然后使软件在后台运行,最后就是双击Shell文件能自 ...

  10. 判断checkbox是否被选中

    jquery判断checked的三种方法: .attr('checked):   //看版本1.6+返回:”checked”或”undefined” ;1.5-返回:true或false .prop( ...