diff --git a/QuickLook/App.xaml.cs b/QuickLook/App.xaml.cs index d9c8a11..7eea314 100644 --- a/QuickLook/App.xaml.cs +++ b/QuickLook/App.xaml.cs @@ -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(); } } } \ No newline at end of file diff --git a/QuickLook/PidHelper.cs b/QuickLook/PidHelper.cs index fcdb922..9dbe811 100644 --- a/QuickLook/PidHelper.cs +++ b/QuickLook/PidHelper.cs @@ -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 {