public void OnCreate(object source, FileSystemEventArgs e)
{
try
{
StreamWriter sw = new StreamWriter("D:/123/Log.txt", true);
sw.WriteLine("File: {0} Created", e.FullPath);
kq(e.FullPath); sw.Close();
//this.BeginInvoke(new UpdateWatchTextDelegate(UpdateWatchText), "Wrote create event to log");
}
catch (IOException)
{
this.BeginInvoke(new UpdateWatchTextDelegate(UpdateWatchText), "Error Writing to log");
}
}
我想问的是为什么在添加了函数kq之后就不能多次运行onCreate了呢,添加之前是可以的呀,请各位帮忙解答一下
{
try
{
StreamWriter sw = new StreamWriter("D:/123/Log.txt", true);
sw.WriteLine("File: {0} Created", e.FullPath);
kq(e.FullPath); sw.Close();
//this.BeginInvoke(new UpdateWatchTextDelegate(UpdateWatchText), "Wrote create event to log");
}
catch (IOException)
{
this.BeginInvoke(new UpdateWatchTextDelegate(UpdateWatchText), "Error Writing to log");
}
}
我想问的是为什么在添加了函数kq之后就不能多次运行onCreate了呢,添加之前是可以的呀,请各位帮忙解答一下
2.可能kq(e.FullPath);中有中断事件代码你的描述与代码太少,无法做出准确判断。
{
ArrayList arr = new ArrayList();//存储所有字符串 try
{
System.IO.FileStream aFile = new FileStream(path, FileMode.Open);//打开文件
System.IO.StreamReader sr = new StreamReader(aFile, System.Text.Encoding.Default);//得到文件
while (!sr.EndOfStream)//读到文件尾
{
string[] row = sr.ReadLine().Replace("\r\n", "a").Split('a');
foreach (string r in row)
{
if (r != "")
arr.Add(r);
}
}
}
catch (IOException e)//抛出异常处理
{
MessageBox.Show("An IO exception has been thrown!");
MessageBox.Show(e.ToString());
return;
}
string dat;//kqtime
dat = (string)arr[1];//数组
string time = dat.Substring(21, 11);
string dat1
dat1 = (string)arr[5];
string location1 = dat1.Substring(0, 6);
string index1 = dat1.Substring(43, 3);
string quality1 = dat1.Substring(55, 4);
string wrw1 = dat1.Substring(71);
SqlConnection thisConnection1 = new SqlConnection(@"server=PC-PC\SQLEXPRESS;Database=xuzhouqixian;Integrated Security=true;Connection Timeout=30;");
thisConnection1.Open();
string sql1 = "insert into kongqi (kqtime,kqlocation,kqindex,kqquality,kqwrw) values('" + time + "','" + location1 + "','" + index1 + "','" + quality1 + "','" + wrw1 + "')";
//insert into SQL(值)values(列)
SqlCommand cmd1 = new SqlCommand(sql1, thisConnection1);
cmd1.ExecuteNonQuery();
thisConnection1.Close(); //关闭
MessageBox.Show("数据已添加进数据库!");
}
大致上是这样的,是不是因为函数中变量的值未释放干净,所以不能有新值呢,大家帮忙看一下……
此消息通过 【CSDN论坛 Winform测试版】 回复!