Kaynağa Gözat

只能运行一个实例

mengjie 7 yıl önce
ebeveyn
işleme
3e5c169f13

+ 1 - 0
HySoftSMS/FrmMain.Designer.cs

@@ -59,6 +59,7 @@
59 59
             this.Controls.Add(this.label1);
60 60
             this.Controls.Add(this.rtb1);
61 61
             this.Name = "FrmMain";
62
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
62 63
             this.Text = "短信发送";
63 64
             this.Load += new System.EventHandler(this.FrmMain_Load);
64 65
             this.ResumeLayout(false);

+ 16 - 3
HySoftSMS/Program.cs

@@ -1,5 +1,6 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3
+using System.Diagnostics;
3 4
 using System.Linq;
4 5
 using System.Threading.Tasks;
5 6
 using System.Windows.Forms;
@@ -14,9 +15,21 @@ namespace HySoftSMS
14 15
         [STAThread]
15 16
         static void Main()
16 17
         {
17
-            Application.EnableVisualStyles();
18
-            Application.SetCompatibleTextRenderingDefault(false);
19
-            Application.Run(new FrmMain());
18
+            Process[] ps = Process.GetProcessesByName("HySoftSMS");
19
+
20
+            if (ps != null && ps.Length > 1)
21
+
22
+            {
23
+
24
+                //发现重复进程
25
+                MessageBox.Show("已经运行了一个实例了。");
26
+            }
27
+            else
28
+            {
29
+                Application.EnableVisualStyles();
30
+                Application.SetCompatibleTextRenderingDefault(false);
31
+                Application.Run(new FrmMain());
32
+            }
20 33
         }
21 34
     }
22 35
 }

+ 0 - 5
HySoftSMS/bin/x86/Debug/Config.ini

@@ -1,5 +0,0 @@
1
-[基础设置]
2
-服务器地址=http://117.158.196.116:8880
3
-
4
-[基础设置1]
5
-服务器地址=http://117.158.196.116:8880