I'm using Microsoft Visual Studio Professional 2022 (64-bit) - Current Version 17.3.1 to build a Console App with .NET Core 6.
The App appends text to a .csv file, and it runs fine.
When I start the App twice (giving different data input) I get:
"access the file because it is being used by another process"
The function that appends to the .csv files is:
    public static readonly object myAppendLock = new();
    public static void AppendToRocket(string outputFilePath, string data) {
      lock (myAppendLock) {
        try {
          using StreamWriter w = File.AppendText(outputFilePath);
          w.Write(data + "\n");
          w.Flush();
          w.Close();
          w.Dispose();
        } catch (Exception ex) {
          Log.WriteLog("AppendToRocket.txt", $"Error: {ex.Message}");
        }
      }
    }
Please help me to understand why I'm getting the "access" error.
Charles