Winify

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ HEAD  →  ?path2? @ 1
/trunk/Winify/Program.cs
@@ -1,18 +1,29 @@
using System;
using System.IO;
using System.Threading;
using System.Windows.Forms;
 
namespace Winify
{
internal class Program
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
 
/// <summary>
@@ -21,19 +32,22 @@
[STAThread]
private static void Main()
{
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
if (Mutex.WaitOne(TimeSpan.Zero, true))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
_form = new Form1();
Application.Run();
Mutex.ReleaseMutex();
return;
}
 
if (Mutex.WaitOne(TimeSpan.Zero, true))
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm(Mutex));
}
finally
{
Mutex.ReleaseMutex();
}
// Foreground current other application window.
Natives.PostMessage(
(IntPtr) Natives.HWND_BROADCAST,
Natives.WM_SHOWME,
IntPtr.Zero,
IntPtr.Zero);
}
 
#endregion