惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
Spread Privacy
Spread Privacy
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
SecWiki News
SecWiki News
腾讯CDC
P
Privacy International News Feed
Webroot Blog
Webroot Blog
J
Java Code Geeks
爱范儿
爱范儿
A
About on SuperTechFans
S
Secure Thoughts
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
DataBreaches.Net
Cloudbric
Cloudbric
Security Archives - TechRepublic
Security Archives - TechRepublic
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Security Latest
Security Latest
Forbes - Security
Forbes - Security
小众软件
小众软件
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threatpost
量子位
MongoDB | Blog
MongoDB | Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Vercel News
Vercel News
Google Online Security Blog
Google Online Security Blog
云风的 BLOG
云风的 BLOG
GbyAI
GbyAI
S
Security @ Cisco Blogs
T
The Exploit Database - CXSecurity.com
Help Net Security
Help Net Security
V
Visual Studio Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 聂微东
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
Attack and Defense Labs
Attack and Defense Labs

博客园 - 林骄

Android note 2010.08.02 v2 2010.08.03 Android note Android Note 2010.08.02 Android Note 2011.08.01 [Biztalk]问题集 - 林骄 - 博客园 Winform导出Excel Excel单元格颜色 判断系统版本 ListView && XmlReader How to open a folder with explorer - 林骄 Print Can't open Infragistics help document How to get local machine date format.如何获取本机时间格式 cannot open user default database WebService Tips 中文全半角转换 装机备忘 Db2中的时间
Windows Service
林骄 · 2009-02-23 · via 博客园 - 林骄

     用Visual Studio创建一个Windows Service非常简便。新建项目,然后选择Windows服务。
     用在一个服务里使用脉冲时间不能用System.Windows.Forms.Timer控件,要使用System.Timers.Timer。
     在Service类里面定义一个私用成员。
     System.Timers.Timer timer = new System.Timers.Timer();     
     然后在OnStart事件里进行设置:
      timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
      timer.Interval = 5000;
      timer.Start();
      首先给Elapsed事件添加委托。这是个脉冲事件,隔Interval 时间就触发一次。下面是timer_Elapsed函数的定义。
       protected void timer_Elapsed(object sender, ElapsedEventArgs e)
        {   
            File.AppendAllText("C:/WindowsService.txt", DateTime.Now.ToString() + ";");
        }
     里面用来放业务逻辑。
     然后调用Start方法,这个步骤是不能少的。
     最后在Service类的OnStop方法中调用Timer的Stop方法。

     接下来进行安装。首先在Service界面点击右键,选择“添加安装程序”。然后在生成菜单中生成该项目。
     接着使用.net的InstallUtil.exe安装服务。
     在“运行”里键入cmd,进入windows命令行,首先进入InstallUtil.exe的安装目录
     cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
     然后使用 installutil  E:\asp.net3.5\IntegrationTest.exe安装自己的项目。
     如果对项目进行了改动,则必须使用installutil -u E:\asp.net3.5\IntegrationTest.exe先进服务卸载,再重新安装。

     调试服务的方法是在项目的Program.cs文件的Main方法中加入下列程序。    

#if DEBUG
            System.Diagnostics.Debugger.Launch();
#endif
     这样在服务启动的时候,会弹出对话框选择调试程序。