window服务调用技巧
2012-06-14 16:59
225 查看
在使用windows服务时,安装能有些不太方便,本文就安装时就使用的技巧提出一点方式,以供大家参考:
windows服务的优点还是加以说明 的1、能够自动运行(需要预先设置运行模式); 2、不要求用户交互,(特别适合在服务器上进行运行);3、在后台运行,如果程序运行时,特别超耗费时间,如备分数据,删除大量数据,多线程捕获数据等等),都可能使用。
但是在安装时,经常会找不到这个关键的文件installutil.exe,因为此文件是用来支持安装过程的。
详细介绍见http://www.cnblogs.com/YanPSun/archive/2010/05/22/1741381.html,
这是就给出一种调用的方式方法。
还要进一步说明的,服务开始执行的语句放到
protected override void OnStart(string[] args)
{
’执行动作的开始
}
停止服务的语句放到
#region 停止服务线程.
protected override void OnStop()
{
'停止工作
base.OnStop();
}
#endregion
以上工作是受服务启动,和停止来执行的。
windows服务的优点还是加以说明 的1、能够自动运行(需要预先设置运行模式); 2、不要求用户交互,(特别适合在服务器上进行运行);3、在后台运行,如果程序运行时,特别超耗费时间,如备分数据,删除大量数据,多线程捕获数据等等),都可能使用。
但是在安装时,经常会找不到这个关键的文件installutil.exe,因为此文件是用来支持安装过程的。
详细介绍见http://www.cnblogs.com/YanPSun/archive/2010/05/22/1741381.html,
这是就给出一种调用的方式方法。
try { System.Uri uri = new Uri(typeof(string).Assembly.CodeBase); string RuntimePath = System.IO.Path.GetDirectoryName(uri.LocalPath); string strInstallUtilPath = System.IO.Path.Combine(RuntimePath, "InstallUtil.exe"); foreach (string arg in System.Environment.GetCommandLineArgs()) { Console.WriteLine(arg); if (arg == "/install") { System.Diagnostics.Process.Start(strInstallUtilPath, "\"" + System.Windows.Forms.Application.ExecutablePath + "\""); return; } else if (arg == "/uninstall") { System.Diagnostics.Process.Start(strInstallUtilPath, "/u \"" + System.Windows.Forms.Application.ExecutablePath + "\""); return; } else if (arg == "/client") { // 启动客户端 Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); using (Form1 frm = new Form1()) { Application.Run(frm); } return; } } } catch (Exception ext) { Console.WriteLine(ext.ToString()); return; }
还要进一步说明的,服务开始执行的语句放到
protected override void OnStart(string[] args)
{
’执行动作的开始
}
停止服务的语句放到
#region 停止服务线程.
protected override void OnStop()
{
'停止工作
base.OnStop();
}
#endregion
以上工作是受服务启动,和停止来执行的。
相关文章推荐
- 删除Window下面的服务技巧
- 如何提高调用Window API函数编程技巧
- [28] Window PowerShell DSC 学习系列----如何用Java调用PowerShell DSC 5.x的oData服务
- 正确捕获 WCF服务调用中发生的异常及处理技巧
- 批处理文件安装卸载window服务程序的技巧
- 如何提高调用Window API函数编程技巧
- window 服务中调试技巧
- 网络服务调用总结
- spring cloud搭建微服务second-fiberhome(三):consul结合config以及bus实现配置文件通过RabbitMQ动态调用
- Silverlight调用WCF服务
- Android窗口管理服务WindowManagerService对输入法窗口(Input Method Window)的管理分析
- nginx在window下的服务安装
- javascript学习随笔(使用window和frame)的技巧
- Spring Cloud 声明式服务调用 Feign
- 使用 gSOAP 通过 HTTP 和 HTTPS 调用由 WSAD 创建的 J2EE Web 服务
- 调试技巧之调用堆栈
- 『翻译』为什么.Net CF在调用HTTPS 的Web服务时失败?!
- 调用第三方服务-axis
- Flex调用GP服务实现按划选范围切割地图(二)
- CXF客户端代码生成与服务调用(二)