如何与 Windows 服务交互?

还不够格啊 2004-09-09 01:28:41
写了一个 Windows 服务,内有一个定时器,缺省定时间隔 2 秒。该服务启动后,有时用户需要更改定时器的定时间隔。该如何与 Windows 服务交互?
...全文
252 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
windinwing 2004-09-23
  • 打赏
  • 举报
回复
我喜欢用配置文件,方法一点,启动后检查配置文件更新时间

protected override void OnStart(string[] args)
{
this.timer1_Elapsed(this,null);
}

private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
//------------ 载入设置文件--------------------------------------------------------------//
DateTime dateSettings = File.GetLastWriteTime(m_SartUpPath + "\\Settings\\Settings.xml");
//检查配置文件是否在服务启动后更改过
if(DateTime.Compare(dateSettings,m_SettingsDate) != 0)
{
m_pFtpServers.Add(new mh_FTP_Server(m_SartUpPath + "\\Settings\\"));

m_SettingsDate = dateSettings;
/*
DataSet ds = new DataSet();
ds.ReadXml(m_SartUpPath + "\\Settings\\Settings.xml");

//---- 获取配置 --------------------------------------//
foreach(DataRow dr in ds.Tables["Servers"].Rows)
{
string ftpRoot = dr["FtpRoot"].ToString();
if(ftpRoot.EndsWith("\\"))
{
ftpRoot = ftpRoot.Substring(0,ftpRoot.Length - 1);
}

string ip = dr["IP"].ToString();
int port = Convert.ToInt32(dr["Port"]);

m_pFtpServers.Add(new mh_FTP_Server(ftpRoot,ip,port));
}*/
//--------------------------------------------------------//
}
}
catch(Exception x)
{
Error.DumpError(x,new System.Diagnostics.StackTrace());
}
}
gbbword 2004-09-23
  • 打赏
  • 举报
回复
同意楼上的!顶一下!
qpl007 2004-09-23
  • 打赏
  • 举报
回复
写服务的OnCustomCommand方法,传入自定义消息:

protected override void OnCustomCommand(int command)
{
if(command == 150)//150为自定义的消息,须在128 和 256 之间
{
//更改定时器的定时间隔
}

base.OnCustomCommand (command);
}
msdn_vipuser 2004-09-22
  • 打赏
  • 举报
回复
支持
CMIC 2004-09-09
  • 打赏
  • 举报
回复
同意 The123(在我地盤這 伱就得聽我的)使用msmq
http://chs.gotdotnet.com/QuickStart/aspplus/default.aspx?url=%2fquickstart%2fhowto%2fdoc%2fmqsend.aspx
popsky 2004-09-09
  • 打赏
  • 举报
回复
该间隔时间的设置应该是在外部的,或配置文件,或注册表,其他程序只要去更改这些外部信息即可
The123 2004-09-09
  • 打赏
  • 举报
回复
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfsystemmessagingmessagequeueclasssendtopic.htm
chNET 2004-09-09
  • 打赏
  • 举报
回复
第一个想法就是在外面有一个接口文件...

111,119

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧