Program.cs
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using log4net.Config;
using log4net.Util.TypeConverters;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Common;
using System.Windows.Forms;
using DeviceLibrary;
using DeviceLibrary.manager;
using System.IO;
namespace AGVControl
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += Application_ThreadException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
XmlConfigurator.Configure(new FileInfo(AppConfigHelper.GetValue(SettingString.log4net_configname)));
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//程序只能运行一次
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(current.ProcessName);
foreach (Process process in processes)
{
if (process.Id == current.Id) continue; //自己
if (process.MainModule.FileName == current.MainModule.FileName)
{
//显示已打开的程序
Window_API.ShowWindow(process.MainWindowHandle, Window_API.SW_RESTORE);
Window_API.SwitchToThisWindow(process.MainWindowHandle, true);
return;
}
}
LogUtil.info("=====程序开始=====");
NodeManager.InitNodesInfos();
IOManager.Start();
DeviceLibrary.manager.MissionManager.InitMission();
ChargePileManager.Init();
AGVManager.Init();
AGVManager.control = new DeviceLibrary.Control();
AGVManager.control.Start();
AGVManager.server = new AgvServer();
AGVManager.server.Start();
DeviceLibrary.manager.MissionManager.Open();
Application.Run(new FrmMain());
AGVManager.control.Stop();
AGVManager.server.Stop();
IOManager.Stop();
DeviceLibrary.manager.MissionManager.Close();
LogUtil.info("=====程序结束=====\r\n");
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
LogUtil.error("CurrentDomain_UnhandledException", (Exception)e.ExceptionObject);
}
private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
LogUtil.error("Application_ThreadException", e.Exception);
}
}
}