码迷,mamicode.com
首页 > 其他好文 > 详细

监听程序

时间:2019-01-17 15:19:56      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:mon   for   filename   RoCE   getc   direct   sse   window   cat   

//运行监听程序
ThreadPool.QueueUserWorkItem((x) =>
{
try
{
bool sqd = true;
Process[] SERVER = Process.GetProcessesByName("MonitorServer");   //获取线程名相同
foreach (Process item in SERVER)
{
if (Path.GetDirectoryName(item.MainModule.FileName).Equals(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location.Replace("/", "\\"))))
{
sqd = false;
break;
}
}
if (sqd)
{
ProcessStartInfo ps = new ProcessStartInfo("MonitorServer.exe");
ps.UseShellExecute = false;
ps.WindowStyle = ProcessWindowStyle.Hidden;   //隐藏线程
Process.Start(ps);
}
}
catch { }
}, new object());

 

关闭窗体   同时关闭监听程序

private void ServerAuto_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
if (e.CloseReason == CloseReason.WindowsShutDown || e.CloseReason == CloseReason.UserClosing)
{
Application.ExitThread();
Application.Exit();
//Process.GetProcessesByName("MonitorServer")[0].Kill();
Process[] SERVER = Process.GetProcessesByName("MonitorServer");
foreach (Process item in SERVER)
{
if (Path.GetDirectoryName(item.MainModule.FileName).Equals(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location.Replace("/", "\\"))))
{
item.Kill();
}
}
Process[] CLIENT = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
foreach (Process item in CLIENT)
{
if (Path.GetDirectoryName(item.MainModule.FileName).Equals(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location.Replace("/", "\\"))))
{
item.Kill();
}
}
}
}
catch { }
}

 

监听程序

标签:mon   for   filename   RoCE   getc   direct   sse   window   cat   

原文地址:https://www.cnblogs.com/yyl001/p/10281856.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!