.NET 2.0 : File.AppendAllText(…) - Thread safe implementation

前端 未结 3 2155
后悔当初
后悔当初 2021-02-13 05:46

As an exercise in idle curiosity more than anything else, consider the following simple logging class:

internal static class Logging
{
    private static object          


        
3条回答
  •  不思量自难忘°
    2021-02-13 06:28

    It is thread safe in the sense that it opens the file with Read sharing, so assuming your filesystem honors file locks, only one thread will be allowed to write to the file at a time. Other threads may, however, get dirty reads if they are attempting to read the same file.

提交回复
热议问题