title: How to avoid this `System.IO.IOException`
body: <pre><code>public static void Main()
  {    
      string username = "", password, chkusername;
      bool vald, chk;
      vald = false;
      string choice = "Y";
  
      while (choice == "Y")
      {                        
          FileStream fs = new FileStream("Users.txt", FileMode.Append, 
              FileAccess.Write, FileShare.Read);
          StreamWriter sw = new StreamWriter(fs);
          Console.WriteLine("Enter Username : ");
          var Createnew = File.ReadAllLines("Users.txt");`
          chkusername = Console.ReadLine();
          foreach(string Dummies in Createnew)
          {
              string[] userline = Dummies.Split('#');
  
              if(userline[0].Equals(chkusername))
              {
                  vald = true;
                  Console.Clear();
                  Console.WriteLine("username already exists please choose another");
                  Console.ReadKey();
                  Console.Clear();
                  break;
              }
  
              chk = vald;
              if (vald == true)
              {
                  Main();
              }
  
              while(choice == "Y")
              {
                  username = chkusername;
                  Console.WriteLine("Enter a Password : ");
                  password = Console.ReadLine();
  
                  sw.WriteLine(username + "#" + password);
                  sw.Flush();
                  sw.Close();
                  fs.Close();
                  Console.WriteLine("Username Created");
                  Console.WriteLine("Do you want to continue ? Y/N");
                  choice = Console.ReadLine();
              }
          }           
      }
  }
  </code></pre>
  
  <p>I get an exception here:</p>
  
  <pre><code> var Createnew = File.ReadAllLines("Users.txt");
  </code></pre>
  
  <blockquote>
    <p>System.IO.IOException: 'The process cannot access the file
    'C:\Users\admin1\source\repos\LumberJackProgram\LumberJackProgram\Users.txt'
    because it is being used by another process.'</p>
  </blockquote>