版博士V2.0程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

103 Zeilen
3.7 KiB

  1. using Models;
  2. using ProductionControl.UI;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Windows.Forms;
  14. namespace ProductionControl
  15. {
  16. internal static class Program
  17. {
  18. /// <summary>
  19. /// 应用程序的主入口点。
  20. /// </summary>
  21. [STAThread]
  22. static void Main()
  23. {
  24. //Application.Run(new Form3());
  25. //return;
  26. //byte[] buff = File.ReadAllBytes(@"D:\AZTCode\HBBank\证书\国mi-生产证书ssl\CFCA_ACS_SM2_OCA31.cer");
  27. //string s = Convert.ToBase64String(buff);
  28. //string bmppath = @"f:\abc.bmp";
  29. //Order order=new Order();
  30. //order.DefectInfoList = new List<DefectInfo>() {
  31. // new DefectInfo(){ X=100,Y=100, Code="dk"},
  32. // new DefectInfo(){ X=200,Y=100, Code="dk"},
  33. // new DefectInfo(){ X=100,Y=200, Code="zk"},
  34. // new DefectInfo(){ X=200,Y=220, Code="xws"},
  35. //};
  36. //Application.Run(new FrmShowDefectImage(bmppath, order));
  37. //return;
  38. Thread.Sleep(500);
  39. Process instance = RunningInstance();
  40. if (instance == null)
  41. {
  42. Application.ThreadException += Application_ThreadException;
  43. Application.EnableVisualStyles();
  44. Application.SetCompatibleTextRenderingDefault(false);
  45. Config.LoadAllConfig();
  46. Service.InitDB.ConnectionString = Config.DBConStr;
  47. //Application.Run(new FrmScannerShow2(new Size(300,300)));
  48. Application.Run(new FrmLogin());
  49. }
  50. else
  51. {
  52. MessageBox.Show("当前程序已经运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 0);
  53. }
  54. }
  55. //不允许有两个程序同时启动
  56. public static Process RunningInstance()
  57. {
  58. Process current = Process.GetCurrentProcess();
  59. Process[] processes = Process.GetProcessesByName(current.ProcessName);
  60. //遍历正在有相同名字运行的例程
  61. foreach (Process process in processes)
  62. {
  63. //忽略现有的例程
  64. if (process.Id != current.Id)
  65. {
  66. //确保例程从EXE文件运行
  67. if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") ==
  68. current.MainModule.FileName)
  69. {
  70. //返回另一个例程实例
  71. return process;
  72. }
  73. }
  74. }
  75. //没有其它的例程,返回Null
  76. return null;
  77. }
  78. static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
  79. {
  80. Exception ex = e.Exception;
  81. using (StreamWriter sw = new StreamWriter(Directory.GetCurrentDirectory() + "\\Log.txt", true))
  82. {
  83. sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  84. sw.WriteLine("Global捕获到未处理异常:" + ex.GetType().ToString());
  85. sw.WriteLine("异常信息:" + ex.Message);
  86. sw.WriteLine("异常堆栈:" + ex.StackTrace);
  87. sw.WriteLine();
  88. }
  89. MessageBox.Show(string.Format("捕获到未处理异常:{0}\r\n异常信息:{1}\r\n异常堆栈:{2}", ex.GetType(), ex.Message, ex.StackTrace));
  90. }
  91. }
  92. }