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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 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方法, 需要一些其他的手段,在此不作介绍(我也没弄懂)。