using System; using System.Threading; using System.Windows.Forms; namespace Widow { internal class Program : IDisposable { #region Static Fields and Constants private static readonly Mutex Mutex = new Mutex(true, Constants.AssemblyGuid); private static Form _form; #endregion #region Constructors, Destructors and Finalizers public void Dispose() { _form?.Dispose(); _form = null; } #endregion #region Private Methods /// /// The main entry point for the application. /// [STAThread] private static void Main() { if (Mutex.WaitOne(TimeSpan.Zero, true)) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); _form = new MainForm(); Application.Run(); Mutex.ReleaseMutex(); return; } // Foreground current other application window. Natives.PostMessage( (IntPtr) Natives.HWND_BROADCAST, Natives.WM_SHOWME, IntPtr.Zero, IntPtr.Zero); } #endregion } }