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

推荐订阅源

cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Engineering at Meta
Engineering at Meta
量子位
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
月光博客
月光博客
A
About on SuperTechFans
博客园 - 聂微东
Spread Privacy
Spread Privacy
B
Blog
NISL@THU
NISL@THU
小众软件
小众软件
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
T
Threatpost
Stack Overflow Blog
Stack Overflow Blog
博客园 - 叶小钗
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
P
Privacy & Cybersecurity Law Blog
C
Cisco Blogs
Cisco Talos Blog
Cisco Talos Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Palo Alto Networks Blog
C
Check Point Blog
O
OpenAI News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
T
Threat Research - Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Know Your Adversary
Know Your Adversary
T
The Exploit Database - CXSecurity.com
N
News and Events Feed by Topic
P
Privacy International News Feed
B
Blog RSS Feed
Google DeepMind News
Google DeepMind News
H
Heimdal Security Blog
Martin Fowler
Martin Fowler
Schneier on Security
Schneier on Security
Webroot Blog
Webroot Blog
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
V2EX - 技术
V2EX - 技术
V
Vulnerabilities – Threatpost
博客园 - 司徒正美
C
CERT Recently Published Vulnerability Notes
H
Hacker News: Front Page
PCI Perspectives
PCI Perspectives

博客园 - antistone

GoogleEarth截图技巧(转) Windows 7 中更改用户主目录 Sybase ASE ADO.NET驱动 乱码问题解决 WinForm中使用Log4NET C# 中用信号量实现读者写者问题 测试Google文件的发布功能 Linux下OpenGL开发 -- 准备篇 FCKEditor工具条定制 FCKEditor的使用-asp 石头汤的故事 在JAVA中读取文件乱码的解决办法 Struts 内容简介(转) Xvid技术中的精彩部分[转] Marshal GetCurrentImage的MSND说明,暂记 C#中数据类型与其他语言中的数据类型之间的对应关系 神州数码网络无线校园网整体解决方案及特点 关于web应用程序安全的思考(序)(转) NHibernate快速指南
C#开发Windows服务入门摘要
antistone · 2008-05-10 · via 博客园 - antistone

参考:http://www.taiwanren.com/blog/article.asp?id=8686

1. 用VS建立一个 Windows Service 类型(中文版为Windows服务)的项目,建立完成后的项目目录类似于:
2.切换到Services1.cs的设计界面, 并打开其属性选项卡:

3. 点击属性页上的添加安装程序链接,具体介绍在参考的文章里写的很详细:"之后,你将获得两个文件Service组件和Program.cs.我们要建立服务的话,首先需要添加专用的安装组件,这步同样很简单,选择服务组件,并切换到设计模式,右键->Add Installer,生成了了安装文件,切换到设计模式,这里你将看到两个组件:ServiceInstaller和ProcessInstaller,这里没有太多需要说明的,大部分是对服务的名称,描述等信息的设置,只有2个地方需要注意下.一个是StartType,有三种选择自动,手动,禁用.如果想要自动启动,那么遍选择Automatic即可.另一个需要注意的属性是Account,选择用户,一般情况下,我们选择Local System即可."

4. 书写自己的业务逻辑代码
5. 编译生成程序并进行服务安装. 此处文章给出了一个较好的生成脚本(YourServiceName为你自己服务的名称):

1 net stop YourServiceName
2 copy /"$(TargetDir)" "$(ProjectDir)bin"
3 "%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe" /u $(ProjectDir)bin\$(TargetFileName)
4 "%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe"  $(ProjectDir)bin\$(TargetFileName)
5 net start YourServiceName
6 

6. 调试. 服务的调试非常的麻烦,网上有很多文章,通过VisualStudio的调试中的"进程附加" 应该可以满足大多数的要求. 如果要调试OnStart和OnStop方法, 需要一些其他的手段,在此不作介绍(我也没弄懂)。