Naruszenie udostępniania plików występuje po utworzeniu pliku?

Próbuję więc utworzyć plik .txt, a następnie zapisać do niego jakieś głupie dane. Ale dostaję naruszenie zasad udostępniania. Wyczuwam, że może tak być, ponieważ próbuję utworzyć StreamWriter dla pliku bezpośrednio po jego utworzeniu, ale to nie ma sensu. Więc jestem trochę zagubiony. Próbowałem usunąć wszystkie inne programy StreamWriters i Readers w klasie, z wyjątkiem błędnej linii, i nadal dochodzi do naruszenia. Błąd, który dostaję

IOException: Sharing violation on path C:\Users\USER\Desktop\Accessible\Assets\IO\Books\A community of learners\frog\frog_status.txt
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options)
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share)
(wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)

Wskazuje na linię:

StreamWriter sw = new StreamWriter(statusTxtPath);

W następującej funkcji:

private IEnumerator GatherStatusInfo(string folderPath, string mediaName) {

        string statusTxtPath = folderPath + @"/" + mediaName + "_status.txt";
        _currentInfoBeingCreated._readingStatusTxtPath = statusTxtPath;

        if(BuildManager.instance._isResetStatusFilesWhenStarting) {
            if(File.Exists(statusTxtPath)) 
                File.Delete(statusTxtPath);
        }

        if(!File.Exists(statusTxtPath)) {
            File.Create(statusTxtPath);
            StreamWriter sw = new StreamWriter(statusTxtPath);
            sw.WriteLine(MediaStatus.Unread);
            sw.WriteLine("0");
            _currentInfoBeingCreated._status = MediaStatus.Unread;
            _currentInfoBeingCreated._pageLastRead = 0; 
            sw.Flush();
            sw.Close();

        } else {

            StreamReader statusReader = new StreamReader(statusTxtPath);
            _currentInfoBeingCreated._status = (MediaStatus) Enum.Parse(typeof(MediaStatus), statusReader.ReadLine());
            _currentInfoBeingCreated._pageLastRead = (int) ConversionUtils.instance.String2Float(statusReader.ReadLine());
            statusReader.Close();
        }

        yield return 0;
    }

Jakiś pomysł, dlaczego ten pies nie chce polować?

questionAnswers(5)

yourAnswerToTheQuestion