window服务调用技巧
来源:互联网 发布:机器人编程java可以吗 编辑:程序博客网 时间:2024/06/05 22:38
在使用windows服务时,安装能有些不太方便,本文就安装时就使用的技巧提出一点方式,以供大家参考:
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 服务中调试技巧
- 如何提高调用Window API函数编程技巧
- 如何提高调用Window API函数编程技巧
- window 服务
- Window服务
- window服务
- window服务
- window 服务
- Window服务
- window服务
- Window服务
- 编写 Window 服务程序
- window系统服务详解
- window系统服务一览表
- Window 服务详解
- 创建window服务
- 删除Window 一个服务
- Stream live media (HTTP) -- using FMS
- 第七章 维持会话状态和设置服务操作的顺序
- java 实现指定日期添加天数
- I2C驱动分析与应用程序编写
- J2EE项目部署,添加到tomcat6.x中的时候弹出theselected server is enabled
- window服务调用技巧
- 第八章 使用工作流实现服务
- Configure HTTP Dynamic Streaming and HTTP Live Streaming (HLS)
- 黑马程序员-java基础 io其他类
- init viewdidload viewdidunload dealloc
- eclipse导入项目,java文件中文乱码
- POJ 3258
- 从 iPhone 模拟器直接录制视频的软件
- C/C++预编译头的概念