日期:2014-05-18 浏览次数:20909 次
//监听端口消息到达时事件委托
public delegate void ErrorEventHandel(string error);
//修改UI属性委托
public delegate void UpdateCurrentMsgtxt(string text);
public partial class MainFrm : Form
{
public MainFrm()
{
InitializeComponent();
//加载控件属性
InfoInitial();//该方法加载控件的属性,显示相关信息,并创建、开启辅助线程
}
//接收到消息后的处理
void receivemsg_on_geterror(string error)
{
//....终止辅助线程(监听端口线程)
TextAppend(error + "\nAuto restartting XXX service...");
ServiceControl.restartservice(servicename, 20000);
TextAppend("OK,service is runing.Getting config information...");
//重启服务后,根据配置文件设定及服务状态重新加载控件的属性
InfoInitial();
}
//修改X控件属性的方法
public void TextAppend(string appendinfo)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new UpdateCurrentMsgtxt(TextAppend));
}
else
{
this.rtxtCurrentInfo.AppendText(appendinfo);
}
}
}
//接收到消息后触发的事件
public event ErrorEventHandel on_geterror;
//监听端口消息
public void getMsgbyUDP(object listenport)
{
//...
while (!shouldstop)
{
//....on_geterror(message);
}
}