1: static class Program
2: {3: private const string concurrencyMtxNameM = @"onlyOne";
4: static bool firstInstance = false;
5: static Mutex concurrencyMtxM;
6: 7: [STAThread]8: static void Main()
9: {10: concurrencyMtxM = new Mutex(true, concurrencyMtxNameM, out firstInstance);
11: 12: if (!firstInstance)
13: {14: MessageBox.Show("Only one instance allowed");
15: return;
16: } 17: Application.EnableVisualStyles();18: Application.SetCompatibleTextRenderingDefault(false);
19: Application.Run(new Form1());
20: } 21: }المصدر : . NET - How to prevent running multiple instances of the same application
ملاحظة: الوصلة باللغة الإيطالية يمكنك استخدام مترجم جوجل لقراءتها باللغة الانجليزية
No comments:
Post a Comment