Fabio Silva

Fabio Silva

  • NA
  • 19
  • 827

File is being used by another progam

May 24 2020 9:24 AM
so, i have this info that i want to be written into a new file, but only if the file does't exist, 
 
string farmSettings = @"Includes/Settings/" + arrResult[1] + ".json";
if (!File.Exists(farmSettings))
using (StreamWriter sw = File.CreateText(farmSettings))
{
TextWriter tw = new StreamWriter(farmSettings);
tw.WriteLine("{");
tw.WriteLine("ID: " + arrResult[0]);
tw.WriteLine("res1: False");
tw.WriteLine("res2: False");
tw.WriteLine("res3: False");
tw.WriteLine("res4: False");
tw.WriteLine("res5: False");
tw.WriteLine("act: False");
tw.WriteLine("Getaway: False");
tw.WriteLine("vip: False");
tw.WriteLine("}");
tw.Close();
}
 
however, its blocking the one timw writing because the file is being used by another program.
 
what is wrong with my code? 
 

Answers (3)