0
我已經做了一個非常基本的Windows服務,其中包含一個函數在系統的本地驅動器中創建文本文件,並且文本文件正在成功創建,但是當我嘗試在該文本文件創建它給下面的錯誤..IO異常在Windows服務中未處理
the process can not access the file because it is used by another process.
這裏是我的windows服務代碼...
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);
}
}
請幫我解決這個問題..提前 謝謝..