title: IO Exception was Unhandled in Windows Service
body: <p>I have made a very basic windows service which contains a function to create text file in local drive of the system and the text file is being created successfully but when i am trying to write a string in the text file created it is giving following error..</p>
  
  <pre><code>the process can not access the file because it is used by another process.
  </code></pre>
  
  <p>And here is my windows service code ...</p>
  
  <pre><code>public void createtextfile() {
          System.IO.File.Create(@"D:\vikas.txt");
      }
  
      protected override void OnStart(string[] args)
      {
  
          createtextfile();
          string conn = "Server=localhost;Port=3306;Database=ipaddress;UID=myUserName;Pwd=myPassword;pooling=false";
          string Query = "Select * from ipaddress";
          MySqlConnection con = new MySqlConnection(conn);
          MySqlCommand comm = new MySqlCommand(Query, con);
          con.Open();
          MySqlDataReader dr = comm.ExecuteReader();
          while (dr.Read())
          {
             String ip=dr["ip"].ToString();
  
             System.IO.File.WriteAllText(@"D:\vikas.txt", ip);
          }
      }
  </code></pre>
  
  <p>Please help me to resolve the issue ..
  Thanks in advance..</p>