C# 防止同一個應用程式運行多個執行個體

來源:互聯網
上載者:User

標籤:winform   style   blog   color   io   使用   ar   for   div   

這裡以C# Winform為例子說明,

最近在實現網路應用的時候,每個程式只能開啟一次,因為會使用同一個連接埠,

所以為了防止客戶不知道的情況下點擊多次或者其他,防止這樣的情況出現,寫了一個小功能實現阻止這件事情發生,

 

說明:

"Chatter"  //程式啟動並執行時候,在資源管理員裡看到的 “ 映像名稱 ”

 

 

 1 using System; 2 using System.Collections.Generic; 3 using System.Windows.Forms; 4 using System.Threading; 5  6 namespace Chatter 7 { 8     static class Program 9     {10         /// <summary>11         /// The main entry point for the application.12         /// </summary>13         [STAThread]14         static void Main()15         {16             bool startNew;17             Mutex m = new Mutex(false, "Chatter", out startNew);18             if (startNew)19             {20                 Application.EnableVisualStyles();21                 Application.SetCompatibleTextRenderingDefault(false);22                 Application.Run(new Chat());23             }24             else25             {26                 MessageBox.Show("Chatter 已經運行中");27             }28         }29     }30 }

 

C# 防止同一個應用程式運行多個執行個體

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.