summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-08-31 17:54:34 +0200
committeremkael <emkael@tlen.pl>2019-10-27 14:53:43 +0100
commit8a3fa1426d45ec8baa557f78d3764d3966b0e1fe (patch)
tree51a5225cc0cdb2f4b229fb809f74e5aefca4bdd2
parent703f99f380b3859eef81b3c23d52ad2f24d84ffa (diff)
Ensuring only one app instance is running
-rw-r--r--spedytor/Program.cs20
1 files changed, 17 insertions, 3 deletions
diff --git a/spedytor/Program.cs b/spedytor/Program.cs
index aafc441..0cd978c 100644
--- a/spedytor/Program.cs
+++ b/spedytor/Program.cs
@@ -1,20 +1,34 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
+using System.Threading;
namespace spedytor
{
static class Program
{
+ static Mutex mutex = new Mutex(false, "Spedytor - emkael.info");
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1());
+ if (!mutex.WaitOne(TimeSpan.FromSeconds(1), false))
+ {
+ MessageBox.Show("Spedytor już działa! Może gdzieś w tle?", "Błąd!", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ try
+ {
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+ Application.Run(new Form1());
+ }
+ finally
+ {
+ mutex.ReleaseMutex();
+ }
}
}
}