From cf88287125f324ffc0a1fcd94f78b15b7c3073e1 Mon Sep 17 00:00:00 2001 From: Tomas Kouba Date: Fri, 26 Nov 2021 18:48:12 +0100 Subject: [PATCH] Add FileShare.ReadWrite for preventing IOException (The process cannot access the file because it is being used by another process) --- Source/ControlLog.xaml.cs | 2 +- Source/LogFile.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/ControlLog.xaml.cs b/Source/ControlLog.xaml.cs index 9e792fe..dd6cb5a 100644 --- a/Source/ControlLog.xaml.cs +++ b/Source/ControlLog.xaml.cs @@ -89,7 +89,7 @@ public void Load(string filePath, CancellationToken ct) { byte[] tempBuffer = new byte[1024 * 1024]; - this.fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); + this.fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); FileInfo fileInfo = new FileInfo(filePath); // Calcs and finally point the position to the end of the line diff --git a/Source/LogFile.cs b/Source/LogFile.cs index bb2daef..e4d2e0f 100644 --- a/Source/LogFile.cs +++ b/Source/LogFile.cs @@ -78,7 +78,7 @@ public void Load(string filePath, SynchronizationContext st, CancellationToken c { byte[] tempBuffer = new byte[1024 * 1024]; - this.fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); + this.fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); FileInfo fileInfo = new FileInfo(filePath); // Calcs and finally point the position to the end of the line