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

推荐订阅源

L
LINUX DO - 热门话题
Stack Overflow Blog
Stack Overflow Blog
B
Blog
WordPress大学
WordPress大学
Project Zero
Project Zero
P
Palo Alto Networks Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
有赞技术团队
有赞技术团队
S
SegmentFault 最新的问题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
T
Tailwind CSS Blog
Forbes - Security
Forbes - Security
F
Full Disclosure
SecWiki News
SecWiki News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hacker News: Ask HN
Hacker News: Ask HN
C
Check Point Blog
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
F
Fortinet All Blogs
Cisco Talos Blog
Cisco Talos Blog
G
Google Developers Blog
J
Java Code Geeks
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recorded Future
Recorded Future
O
OpenAI News
Spread Privacy
Spread Privacy
MongoDB | Blog
MongoDB | Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Cybersecurity and Infrastructure Security Agency CISA
S
Securelist
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
IT之家
IT之家
U
Unit 42
腾讯CDC
S
Security Affairs
C
Cisco Blogs
Schneier on Security
Schneier on Security
The Last Watchdog
The Last Watchdog
B
Blog RSS Feed
宝玉的分享
宝玉的分享
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
Cyberwarzone
Cyberwarzone
T
The Blog of Author Tim Ferriss

博客园 - 林骄

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
     这样在服务启动的时候,会弹出对话框选择调试程序。