参数化窗口服务 [英] Parameterised Window service

查看:86
本文介绍了参数化窗口服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我已经创建了一个窗口服务,但我希望它可以进行参数设置。



使用的示例代码是:

 受保护 覆盖  void  OnStart( string  [] args)
{
.OnStart(参数);
string name = args [ 0 ];
string text = args [ 1 ];

FileStream fs = new FileStream(name,FileMode.OpenOrCreate,FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.BaseStream.Seek( 0 ,SeekOrigin.End);
m_streamWriter.WriteLine(text + DateTime.Now.ToShortDateString()+ + DateTime .Now.ToShortTimeString()+ \ n);
m_streamWriter.Flush();
m_streamWriter.Close();
}





我可以在安装后从窗口服务的属性发送两个参数,但问题是它甚至在传递单个参数时也开始了。

是否有任何方法可以提示用户提供两个输入...以及任何其他使窗口服务参数化的好方法?

解决方案

引用:

有什么方法可以提示用户提供两个输入



根据Windows服务的原则提示用户输入:在没有用户可见窗口的情况下在后台运行。



您可以这样做:编写另一个程序进行配置。此配置程序不是服务,并显示用户可以指定配置的窗口。此配置可以保存到文件中,并且您的服务在启动时会读取此配置文件。


Hi ,

I have created a window service but i want it to make parameterised.

Sample code used is :

protected override void OnStart(string[] args)
       {
           base.OnStart(args);
           string name = args[0];
           string text = args[1];

           FileStream fs = new FileStream(name, FileMode.OpenOrCreate, FileAccess.Write);
           StreamWriter m_streamWriter = new StreamWriter(fs);
           m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
           m_streamWriter.WriteLine(text + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "\n");
           m_streamWriter.Flush();
           m_streamWriter.Close();
       }



I can send two parameter also from properties of window service after installing this but the problem is it is getting started even on passing single parameter.
is there any way that i can prompt user to give two inputs...and any other good way to make window service parameterised??

解决方案

Quote:

is there any way that i can prompt user to give two inputs


Prompting the user for input when starting a bit against the principles of a Windows Service: running in the background without user-visible windows.

You can do this instead: write another program for configuration. This config program is not a service and shows a window where the user can specify configuration. This configuration can get saved to a file, and your service reads this configuration file when it starts.


这篇关于参数化窗口服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆