Skip to content

Commit

Permalink
only allow a single instance
Browse files Browse the repository at this point in the history
  • Loading branch information
radj307 committed Feb 22, 2022
1 parent 1773368 commit a0e4d0f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion VolumeControl/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;

namespace VolumeControl
{
internal static class Program
Expand All @@ -6,8 +10,19 @@ internal static class Program
[STAThread]
private static void Main()
{
Process thisProc = Process.GetCurrentProcess();
foreach (Process otherInst in Process.GetProcessesByName(thisProc.ProcessName))
if (thisProc.Id != otherInst.Id)
throw new Exception("An instance of Volume Control is already running!");

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

ApplicationConfiguration.Initialize();
Application.Run(new VolumeControlForm());

var form = new VolumeControlForm();

Application.Run(form);
}
}
}

0 comments on commit a0e4d0f

Please sign in to comment.