windows mobile 只能運行一個程序實例

 1 static class Program
 2     {
 3         [System.Runtime.InteropServices.DllImport("coredll.Dll", SetLastError = true)]
 4         private static extern int ReleaseMutex(IntPtr hMutex);
 5 
 6         [System.Runtime.InteropServices.DllImport("coredll.Dll", SetLastError = true)]
 7         private static extern IntPtr CreateMutex(string lpMutexAttributes, bool bInitialOwner, string lpName);
 8         /// <summary>
 9         /// 應用程序的主入口點。
10         /// </summary>
11         [MTAThread]
12         static void Main()
13         {
14             try
15             {
16                 IntPtr hMutex = CreateMutex(null, false, "XXXXX");
17                 if (System.Runtime.InteropServices.Marshal.GetLastWin32Error() != 0183) 18                 {
19                     Application.Run(new FrmMain());
20                 }
21                 else
22                 {
23                     MessageBox.Show("程序已經運行.", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
24                     ReleaseMutex(hMutex);
25                 }
26             }
27             catch (Exception)
28             {
29 
30                 MessageBox.Show("發生未知錯誤,程序退出!");
31                 Application.Exit();
32             }
33 
34         }
35     }
相關文章
相關標籤/搜索