fix FileShare mismatch when reading .pid file created by another instance

This commit is contained in:
Paddy Xu
2017-05-18 23:43:01 +03:00
parent dee7878bf3
commit 44187f845a
2 changed files with 9 additions and 2 deletions

View File

@@ -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();
}
}
}

View File

@@ -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
{