版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

71 строка
2.3 KiB

  1. using Newtonsoft.Json.Linq;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Text.RegularExpressions;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace AssistClient
  13. {
  14. internal static class Program
  15. {
  16. /// <summary>
  17. /// 应用程序的主入口点。
  18. /// </summary>
  19. [STAThread]
  20. static void Main()
  21. {
  22. Thread.Sleep(500);
  23. Process instance = RunningInstance();
  24. if (instance == null)
  25. {
  26. Application.EnableVisualStyles();
  27. Application.SetCompatibleTextRenderingDefault(false);
  28. Config.LoadAllConfig();
  29. while (string.IsNullOrWhiteSpace(Config.DBConStr))
  30. {
  31. Application.Run(new FrmSysSetting());
  32. Config.LoadAllConfig();
  33. }
  34. Service.InitDB.ConnectionString = Config.DBConStr;
  35. //Application.Run(new Form1());
  36. Application.Run(new FrmLogin());
  37. }
  38. else
  39. {
  40. MessageBox.Show("当前程序已经运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 0);
  41. }
  42. }
  43. //不允许有两个程序同时启动
  44. public static Process RunningInstance()
  45. {
  46. Process current = Process.GetCurrentProcess();
  47. Process[] processes = Process.GetProcessesByName(current.ProcessName);
  48. //遍历正在有相同名字运行的例程
  49. foreach (Process process in processes)
  50. {
  51. //忽略现有的例程
  52. if (process.Id != current.Id)
  53. {
  54. //确保例程从EXE文件运行
  55. if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") ==
  56. current.MainModule.FileName)
  57. {
  58. //返回另一个例程实例
  59. return process;
  60. }
  61. }
  62. }
  63. //没有其它的例程,返回Null
  64. return null;
  65. }
  66. }
  67. }