大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> NET专区 -> 用C#创建Windows(NT)服务(转)

用C#创建Windows(NT)服务(转)

时间: 2021-07-31 作者:daque

主假如比拟一下用vs.net写windows service的简略性。 间回复上头的那篇io读写题目 异读: windows效劳在visual studio 往日的本子中叫nt效劳,在vs.net起用了新的称呼。 用visual c# 创造windows效劳不是一件艰巨的事,正文就将引导你一步一步创造 一个windows效劳并运用它。这个效劳在启用和遏止时,向一个文本文献中写入文 字消息。这个小本领来自于msdn,然而此刻步调编写的越发明显,而且你不妨按照 你的须要窜改它。 windows效劳在visual studio 往日的本子中叫nt效劳,在vs.net起用了新的称呼。 用visual c# 创造windows效劳不是一件艰巨的事,正文就将引导你一步一步创造 一个windows效劳并运用它。这个效劳在启用和遏止时,向一个文本文献中写入文 字消息。这个小本领来自于msdn,然而此刻步调编写的越发明显,而且你不妨按照 你的须要窜改它。 第一步:创造效劳框架 visual c# 工程中采用 windows 效劳(windows service)选项...... 引导向工程文献中减少webservice1.cs类... 第二步:向效劳中减少功效 在 webservice1.cs中咱们不妨看到,有两个被忽视的因变量 onstart和onstop。 protected override void onstart(string[] args) { filestream fs = new filestream(@"c:\temp\mcwindowsservice.txt" , filemode.openorrcreate, fileaccess.write); streamwriter m_streamwriter = new streamwriter(fs); m_streamwriter.basestream.seek(0, seekorigin.end); m_streamwriter.writeline(" mcwindowsservice: service started \n"); m_streamwriter.flush(); } protected override void onstop() { filestream fs = new filestream(@"c:\temp\mcwindowsservice.txt" , filemode.openorrcreate, fileaccess.write); streamwriter m_streamwriter = new streamwriter(fs); m_streamwriter.basestream.seek(0, seekorigin.end); m_streamwriter.writeline(" mcwindowsservice: service stopped \n"); m_streamwriter.flush(); } 第三步:安置和运转效劳 这个运用步调结果天生一个exe文献mcwinservice.exe。要备案这个效劳,你需 启用发端菜单中的吩咐行按如次办法挪用 installutil:installutil c:\mcwebservice\bin\debug\mcwebservice.exe。 要卸载效劳,运用 /u 选项: installutil /u c:\mcwebservice\bin\debug\mcwebservice.exe。 第四步:启用和遏止效劳 mycomputer->manage->/ services and applications/services or: computer management/services 你就能看到效劳 mcwinservice,右键单击弹出菜单中有启用和遏止选项 第六步:尝试效劳

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.