|
@@ -15,6 +15,7 @@ using XHWK.WKTool.Skin;
|
15
|
15
|
|
16
|
16
|
namespace XHWK.WKTool
|
17
|
17
|
{
|
|
18
|
+ using System.Runtime.InteropServices;
|
18
|
19
|
using system;
|
19
|
20
|
|
20
|
21
|
public partial class App
|
|
@@ -316,7 +317,6 @@ namespace XHWK.WKTool
|
316
|
317
|
Console.WriteLine(@"初始化APP");
|
317
|
318
|
LogHelper.InitLog4Net();
|
318
|
319
|
myloading = new LoadDialog();
|
319
|
|
- StopSameProcess();
|
320
|
320
|
Killffmpeg();
|
321
|
321
|
try
|
322
|
322
|
{
|
|
@@ -379,30 +379,31 @@ namespace XHWK.WKTool
|
379
|
379
|
|
380
|
380
|
#region 杀死已存在的进程
|
381
|
381
|
|
382
|
|
- /// <summary>
|
383
|
|
- /// 结束已运行的程序
|
384
|
|
- /// </summary>
|
385
|
|
- private static void StopSameProcess()
|
|
382
|
+ [DllImport("User32.dll")]
|
|
383
|
+ private static extern int FindWindow(string className, string windowName);
|
|
384
|
+
|
|
385
|
+ [DllImport("user32.dll")]
|
|
386
|
+ public static extern bool SetForegroundWindow(int hWnd);
|
|
387
|
+
|
|
388
|
+ private static void CheckProcess()
|
386
|
389
|
{
|
|
390
|
+ Console.WriteLine(@"程序启动");
|
387
|
391
|
Process current = Process.GetCurrentProcess();
|
388
|
|
- Process[] processList = Process.GetProcesses();
|
389
|
|
- foreach (Process process in processList)
|
|
392
|
+ //获取欲启动进程名
|
|
393
|
+ string strProcessName = Process.GetCurrentProcess().ProcessName;
|
|
394
|
+ var processList = Process.GetProcessesByName(strProcessName);
|
|
395
|
+ if (processList.Length <= 1)
|
390
|
396
|
{
|
391
|
|
- if (process.ProcessName.ToUpper() == "星火微课")
|
392
|
|
- {
|
393
|
|
- if (process.Id != current.Id) //忽略当前进程
|
394
|
|
- {
|
395
|
|
- try
|
396
|
|
- {
|
397
|
|
- process.Kill(); //结束进程
|
398
|
|
- }
|
399
|
|
- catch (Exception)
|
400
|
|
- {
|
401
|
|
- // ignored
|
402
|
|
- }
|
403
|
|
- }
|
404
|
|
- }
|
|
397
|
+ return;
|
|
398
|
+ }
|
|
399
|
+ MessageWindow.Show("当前程序已在运行,请勿重复运行。");
|
|
400
|
+ foreach (var process in processList)
|
|
401
|
+ {
|
|
402
|
+ if (process.Id == current.Id) continue;
|
|
403
|
+ int hWnd = FindWindow(null, process.MainWindowTitle);
|
|
404
|
+ SetForegroundWindow(hWnd);
|
405
|
405
|
}
|
|
406
|
+ Environment.Exit(1); //退出新打开的程序
|
406
|
407
|
}
|
407
|
408
|
|
408
|
409
|
/// <summary>
|
|
@@ -693,6 +694,7 @@ namespace XHWK.WKTool
|
693
|
694
|
{
|
694
|
695
|
RegisterEvents();
|
695
|
696
|
base.OnStartup(e);
|
|
697
|
+ CheckProcess();
|
696
|
698
|
}
|
697
|
699
|
}
|
698
|
700
|
}
|