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);
}
}
请帮我解决这个问题..提前 谢谢..