Commit a10b0e99 张东亮

监控软件进程显示问题

1 个父辈 fb278a4d
...@@ -77,7 +77,6 @@ ...@@ -77,7 +77,6 @@
<Compile Include="util\SMF.cs" /> <Compile Include="util\SMF.cs" />
<Compile Include="util\TcpServer.cs" /> <Compile Include="util\TcpServer.cs" />
<Compile Include="util\UdpServer.cs" /> <Compile Include="util\UdpServer.cs" />
<Compile Include="util\WindowUtil.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<WCFMetadata Include="Service References\" /> <WCFMetadata Include="Service References\" />
......
...@@ -38,13 +38,13 @@ namespace Common ...@@ -38,13 +38,13 @@ namespace Common
MessageBox.Show(ex.ToString()); MessageBox.Show(ex.ToString());
} }
} }
public static Process StartProcess(string appName, string baseDir = @".\",int waitIdle=5000) public static Process StartProcess(string appName, string baseDir = @".\", int waitIdle = 5000)
{ {
try try
{ {
Process process = new Process(); Process process = new Process();
process.StartInfo = new System.Diagnostics.ProcessStartInfo(); process.StartInfo = new System.Diagnostics.ProcessStartInfo();
process.StartInfo.FileName = appName+".exe"; process.StartInfo.FileName = appName + ".exe";
process.StartInfo.WorkingDirectory = baseDir; process.StartInfo.WorkingDirectory = baseDir;
process.Start(); process.Start();
process.WaitForInputIdle(waitIdle); process.WaitForInputIdle(waitIdle);
...@@ -78,6 +78,26 @@ namespace Common ...@@ -78,6 +78,26 @@ namespace Common
return processRun; return processRun;
} }
public static bool IsRun(string process)
{
bool processRun = false;
try
{
System.Diagnostics.Process[] processList = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process process2 in processList)
{
if (process2.ProcessName == process)
{
processRun = true;
}
}
}
catch { }
return processRun;
}
public static bool CloseProcess(Process process) public static bool CloseProcess(Process process)
{ {
bool sc = false; bool sc = false;
...@@ -97,5 +117,23 @@ namespace Common ...@@ -97,5 +117,23 @@ namespace Common
catch { sc = true; } catch { sc = true; }
return sc; return sc;
} }
public static bool CloseProcess(string process)
{
bool sc = false;
try
{
System.Diagnostics.Process[] processList = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process process2 in processList)
{
if (process2.ProcessName == process)
{
process2.Kill();
sc = process2.WaitForExit(100000);
}
}
}
catch { sc = true; }
return sc;
}
} }
} }
...@@ -132,6 +132,7 @@ ...@@ -132,6 +132,7 @@
<Compile Include="userControl\ToucDownBtn.cs"> <Compile Include="userControl\ToucDownBtn.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="WindowManager.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="userControl\AxisMoveControl.resx"> <EmbeddedResource Include="userControl\AxisMoveControl.resx">
......
using log4net.Util; using Common;
using OnlineStore.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using System.Xml.Linq;
namespace Common namespace TheMachine
{ {
public class WindowManager
{
public static List<WindInfo> windInfos = new List<WindInfo>();
static string baseDir = Application.StartupPath + @"\Modules\";
public static void Start()
{
foreach (var item in windInfos)
{
try
{
if (ProcessUtil.IsRun(item.Name))
{
ProcessUtil.CloseProcess(item.Name);
Thread.Sleep(2000);
}
item.ProcessInfo = ProcessUtil.StartProcess(item.Name, baseDir + $"{item.Name}\\", 60000);
}
catch (Exception ex)
{
LogUtil.error($"程序{item.Name}启动失败", ex);
}
}
}
public static void Show()
{
foreach (var item in windInfos)
item.WindowHandle = WindowUtil.PutIntoForm(item.Parent, item.Name);
}
public static void Hide()
{
foreach (var item in windInfos)
{
if (item.WindowHandle != IntPtr.Zero)
{
item.WindowHandle = IntPtr.Zero;
WindowUtil.RemoveFromForm(item.Name);
}
}
}
}
public class WindInfo
{
public string Name { get; set; }
public IntPtr WindowHandle { get; set; }
public Panel Parent { get; set; }
public Process ProcessInfo { get; set; }
public const string IPCamera = "IPCamera";
}
public class WindowUtil public class WindowUtil
{ {
public const int WM_CLOSE = 0x0010; public const int WM_CLOSE = 0x0010;
......
...@@ -166,7 +166,6 @@ ...@@ -166,7 +166,6 @@
<Compile Include="UC\UC_SetUserPassword.designer.cs"> <Compile Include="UC\UC_SetUserPassword.designer.cs">
<DependentUpon>UC_SetUserPassword.cs</DependentUpon> <DependentUpon>UC_SetUserPassword.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="WindowManager.cs" />
<EmbeddedResource Include="AboutBox1.resx"> <EmbeddedResource Include="AboutBox1.resx">
<DependentUpon>AboutBox1.cs</DependentUpon> <DependentUpon>AboutBox1.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
......
using Common;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TheMachine
{
internal class WindowManager
{
public static List<WindInfo> windInfos = new List<WindInfo>();
static string baseDir = Application.StartupPath + @"\Modules\";
public static void Start()
{
foreach (var item in windInfos)
{
try
{
item.ProcessInfo = ProcessUtil.StartProcess(item.Name, baseDir + $"{item.Name}\\", 60000);
}
catch (Exception ex)
{
LogUtil.error($"程序{item.Name}启动失败", ex);
}
}
}
public static void Show()
{
foreach (var item in windInfos)
item.WindowHandle = WindowUtil.PutIntoForm(item.Parent, item.Name);
}
public static void Hide()
{
foreach (var item in windInfos)
{
if(item.WindowHandle != IntPtr.Zero)
{
item.WindowHandle = IntPtr.Zero;
WindowUtil.RemoveFromForm(item.Name);
}
}
}
}
class WindInfo
{
public string Name { get; set; }
public IntPtr WindowHandle { get; set; }
public Panel Parent { get; set; }
public Process ProcessInfo { get; set; }
public const string IPCamera = "IPCamera";
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!