title: System.IO.IOException: 'The process cannot access the file '@.txt' because it is being used by another process.'
body: <p>I am new to programming and I have a question. If I have two functions, one creates a text file and writes into it, while the other opens the same text file and reads from it.</p>
  
  <p>The error I get is: </p>
  
  <blockquote>
    <p>System.IO.IOException: 'The process cannot access the file '@.txt'
    because it is being used by another process.'</p>
  </blockquote>
  
  <p>I have tried setting seperate timers to each of the functions but it still does not work. I think the best way would be that the function two does not start until function one ends.</p>
  
  <p>Can you help me achieve this?
  Thank you very much!
  Mike</p>
  
  <p>Source code:</p>
  
  <pre><code>public Form1() {
      InitializeComponent();
      System.Timers.Timer timerButtona1 = new System.Timers.Timer();
      timerButtona1.Elapsed += new ElapsedEventHandler(tickTimera1);
      timerButtona1.Interval = 3003;
      timerButtona1.Enabled = true;
  }
  
  private async void tickTimera1(object source, ElapsedEventArgs e) {
      function1();
      function2();
  }
  
  void function1() {
      List&lt;string&gt; linki = new List&lt;string&gt;();
  
      linki.Add("https://link1.net/");
      linki.Add("https://link2.net/");
      linki.Add("https://link3.net/");
  
      List&lt;string&gt; fileNames = new List&lt;string&gt;();
  
      fileNames.Add("name1");
      fileNames.Add("name2");
      fileNames.Add("name3");
  
      for (int x = 0; x &lt; fileNames.Count; x++) {
          GET(linki[x], fileNames[x]);
          //System.Threading.Thread.Sleep(6000);
      }
  }
  
  async void GET(string link, string fileName) {
      var ODGOVOR = await PRENOS_PODATKOV.GetStringAsync(link);
      File.WriteAllText(@"C:\Users\...\" + fileName + ".txt", ODGOVOR);
  }
  
  void function2() {
      string originalText = File.ReadAllText(@"C:\Users\...\fileName.txt", Encoding.Default);
      dynamic modifiedText = JsonConvert.DeserializeObject(originalText);
      //then i then i read from the same text files and use some data from it..
  }
  </code></pre>