Hi I am fairly new to C# and am testing a simple openFileDialog program. The code I currently wrote seems to be doing its job, however, the output is produced twice. Any help would be appreciated.
My code:
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
}
private void OnChanged(object source, FileSystemEventArgs e)
{
MessageBox.Show("copying done");
StreamReader inStream = new StreamReader(destFile);
string line;
string[] lineSplit;
bool errorFound = false;
while ((line = inStream.ReadLine()) != null)
{
lineSplit = line.Split(' ');
for (int i = 0; i < lineSplit.Length; i++)
{
if (lineSplit[i] == textBox2.Text)
{
errorFound = true;
MessageBox.Show("Error found in " + e.Name);
MessageBox.Show("Exiting");
break;
}
}
}
inStream.Close();
}
The output:
Copying Done
File: ..Changed
Copying Done
File: ..Changed
Just wondering why does it print twice?