writealltext

File.WriteAllText and Concurrent Accesses

人盡茶涼 提交于 2019-12-30 08:08:13
问题 Suppose I'm writing a very long string to a file using File.WriteAllText, and another thread or process is trying to read the same file. Would it throw any exception? In other words, what is the FileShare parameter that the File.WriteAllText method uses? It's not written in the documentation! 回答1: This is the source code from .net Framework 4.0. clearly StreamWriter is used that Uses FileShare.Read Internally. [SecuritySafeCritical] public static void WriteAllText(string path, string contents

File.WriteAllText and Concurrent Accesses

梦想的初衷 提交于 2019-12-30 08:08:07
问题 Suppose I'm writing a very long string to a file using File.WriteAllText, and another thread or process is trying to read the same file. Would it throw any exception? In other words, what is the FileShare parameter that the File.WriteAllText method uses? It's not written in the documentation! 回答1: This is the source code from .net Framework 4.0. clearly StreamWriter is used that Uses FileShare.Read Internally. [SecuritySafeCritical] public static void WriteAllText(string path, string contents