mirror of
https://github.com/QL-Win/QuickLook.git
synced 2026-02-28 01:00:17 +08:00
fix FileShare mismatch when reading .pid file created by another instance
This commit is contained in:
@@ -16,6 +16,8 @@ namespace QuickLook
|
||||
public static readonly string AppPath = Path.GetDirectoryName(AppFullPath);
|
||||
public static bool RunningAsViewer;
|
||||
|
||||
private static bool _duplicated;
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
|
||||
@@ -64,6 +66,8 @@ namespace QuickLook
|
||||
|
||||
if (PidHelper.GetRunningInstance() != -1)
|
||||
{
|
||||
_duplicated = true;
|
||||
|
||||
MessageBox.Show("QuickLook is already running in the background.");
|
||||
|
||||
Current.Shutdown();
|
||||
@@ -86,7 +90,8 @@ namespace QuickLook
|
||||
TrayIconManager.GetInstance().Dispose();
|
||||
BackgroundListener.GetInstance().Dispose();
|
||||
|
||||
PidHelper.DeletePid();
|
||||
if (!_duplicated)
|
||||
PidHelper.DeletePid();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,9 @@ namespace QuickLook
|
||||
return -1;
|
||||
|
||||
var ppid = -1;
|
||||
int.TryParse(File.ReadAllText(pid), out ppid);
|
||||
using (var file = File.Open(pid, FileMode.Open, FileAccess.Read,FileShare.ReadWrite))
|
||||
using (var sr = new StreamReader(file))
|
||||
int.TryParse(sr.ReadToEnd(), out ppid);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user