@@ -19,23 +19,20 @@ public IpcChannel()
19
19
{
20
20
try
21
21
{
22
- _singletonMutex = new Mutex ( false , "SourceGit_2994509B-4906-4A48-9A45-55C1836A8208" , out _isFirstInstance ) ;
23
-
24
- if ( _isFirstInstance )
25
- {
26
- _server = new NamedPipeServerStream (
27
- "SourceGitIPCChannel" ,
28
- PipeDirection . In ,
29
- - 1 ,
30
- PipeTransmissionMode . Byte ,
31
- PipeOptions . Asynchronous | PipeOptions . CurrentUserOnly ) ;
32
- _cancellationTokenSource = new CancellationTokenSource ( ) ;
33
- Task . Run ( StartServer ) ;
34
- }
22
+ _singletoneLock = File . Open ( Path . Combine ( Native . OS . DataDir , "process.lock" ) , FileMode . OpenOrCreate , FileAccess . ReadWrite , FileShare . None ) ;
23
+ _isFirstInstance = true ;
24
+ _server = new NamedPipeServerStream (
25
+ "SourceGitIPCChannel" ,
26
+ PipeDirection . In ,
27
+ - 1 ,
28
+ PipeTransmissionMode . Byte ,
29
+ PipeOptions . Asynchronous | PipeOptions . CurrentUserOnly ) ;
30
+ _cancellationTokenSource = new CancellationTokenSource ( ) ;
31
+ Task . Run ( StartServer ) ;
35
32
}
36
33
catch
37
34
{
38
- // IGNORE
35
+ _isFirstInstance = false ;
39
36
}
40
37
}
41
38
@@ -70,7 +67,7 @@ public void SendToFirstInstance(string cmd)
70
67
public void Dispose ( )
71
68
{
72
69
_cancellationTokenSource ? . Cancel ( ) ;
73
- _singletonMutex . Dispose ( ) ;
70
+ _singletoneLock ? . Dispose ( ) ;
74
71
}
75
72
76
73
private async void StartServer ( )
@@ -99,7 +96,7 @@ private async void StartServer()
99
96
}
100
97
}
101
98
102
- private Mutex _singletonMutex = null ;
99
+ private FileStream _singletoneLock = null ;
103
100
private bool _isFirstInstance = false ;
104
101
private NamedPipeServerStream _server = null ;
105
102
private CancellationTokenSource _cancellationTokenSource = null ;
0 commit comments