Skip to content

Commit 161b3bf

Browse files
committed
Add only one single instance per user restriction
1 parent 535c497 commit 161b3bf

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/Program.fs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ open System
44
open System.IO
55
open System.Net
66
open System.Reflection
7+
open System.Threading
78
open Avalonia.Logging
89
open Elmish
910
open Avalonia
@@ -187,9 +188,16 @@ module Program =
187188

188189
[<EntryPoint>]
189190
let main(args: string[]) =
190-
AppBuilder
191-
.Configure<App>()
192-
.UsePlatformDetect()
193-
.LogToTrace(LogEventLevel.Warning)
194-
.UseSkia()
195-
.StartWithClassicDesktopLifetime(args)
191+
let mutexName = $"Global\\{Environment.UserName}"
192+
let appUserInstanceAlreadyExists, _ = Mutex.TryOpenExisting(mutexName)
193+
if appUserInstanceAlreadyExists
194+
then
195+
1 // Application instance for this user already launched
196+
else
197+
use mutex = new Mutex(false, mutexName)
198+
AppBuilder
199+
.Configure<App>()
200+
.UsePlatformDetect()
201+
.LogToTrace(LogEventLevel.Warning)
202+
.UseSkia()
203+
.StartWithClassicDesktopLifetime(args)

0 commit comments

Comments
 (0)