mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 20:54:59 +00:00
refactor: use lock file instead of named mutex since the second one may not work on other platforms
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
9ebde1943e
commit
90b37663ed
1 changed files with 13 additions and 16 deletions
|
@ -19,10 +19,8 @@ namespace SourceGit.Models
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_singletonMutex = new Mutex(false, "SourceGit_2994509B-4906-4A48-9A45-55C1836A8208", out _isFirstInstance);
|
_singletoneLock = File.Open(Path.Combine(Native.OS.DataDir, "process.lock"), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
|
||||||
|
_isFirstInstance = true;
|
||||||
if (_isFirstInstance)
|
|
||||||
{
|
|
||||||
_server = new NamedPipeServerStream(
|
_server = new NamedPipeServerStream(
|
||||||
"SourceGitIPCChannel",
|
"SourceGitIPCChannel",
|
||||||
PipeDirection.In,
|
PipeDirection.In,
|
||||||
|
@ -32,10 +30,9 @@ namespace SourceGit.Models
|
||||||
_cancellationTokenSource = new CancellationTokenSource();
|
_cancellationTokenSource = new CancellationTokenSource();
|
||||||
Task.Run(StartServer);
|
Task.Run(StartServer);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// IGNORE
|
_isFirstInstance = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +67,7 @@ namespace SourceGit.Models
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_cancellationTokenSource?.Cancel();
|
_cancellationTokenSource?.Cancel();
|
||||||
_singletonMutex.Dispose();
|
_singletoneLock?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void StartServer()
|
private async void StartServer()
|
||||||
|
@ -99,7 +96,7 @@ namespace SourceGit.Models
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mutex _singletonMutex = null;
|
private FileStream _singletoneLock = null;
|
||||||
private bool _isFirstInstance = false;
|
private bool _isFirstInstance = false;
|
||||||
private NamedPipeServerStream _server = null;
|
private NamedPipeServerStream _server = null;
|
||||||
private CancellationTokenSource _cancellationTokenSource = null;
|
private CancellationTokenSource _cancellationTokenSource = null;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue