C#C
C#17mo ago
MSCP

StreamWriter writing some lines multiple times

I'm using StreamWriter to write project data into a file, but more often than not I'll get some lines written twice and maybe even three times. Is this a bug with my code or something else?
Code:
// Write the project data into the file
            using (StreamWriter PFWriter = new StreamWriter(ProjectConfigFilePath, false))
            {
                PFWriter.WriteLine("[PROJECT_INFO]");
                PFWriter.WriteLine(ProjectName);
                
                if (OpenScene.Contains(Path.GetDirectoryName(ProjectConfigFilePath)))
                {
                    PFWriter.WriteLine($"INSIDE_PROJECT_DIR -> {OpenScene.Replace(Path.GetDirectoryName(ProjectConfigFilePath), "")}");
                }
                else
                {
                    PFWriter.WriteLine(OpenScene);
                }

                PFWriter.WriteLine("[END_PROJECT_INFO]");
                PFWriter.WriteLine("\n[SCENES]");
                
                ConsoleUtils.StatusWrite(string.Join(", ", SceneList));

                foreach (string Scene in SceneList)
                {

                    if (Scene.Contains(Path.GetDirectoryName(ProjectConfigFilePath)))
                    {
                        PFWriter.WriteLine($"INSIDE_PROJECT_DIR -> {Scene.Replace(Path.GetDirectoryName(ProjectConfigFilePath), "")}");
                    }
                    else
                    {
                        PFWriter.WriteLine(Scene);
                    }
                }

                PFWriter.WriteLine("[END_SCENES]");
                PFWriter.Flush();
            }
Was this page helpful?