I am building a program that is supposed to watch some project folder for change in source code and then send these changes somewhere and in the process, log the files that were changed in a Windows Form TextBox.
The code looks something like this:
void Form_Load(object sender, EventArgs e)
{
FileSystemWatcher fsw = new FileSystemWatcher("C:\\test");
fsw.Created += File_Created;
}
void File_Created(object sender, FileSystemEventArgs e)
{
string name = Path.GetFileName(e.FullPath);
logs.Text += name + Environment.NewLine;
}
Of course, this is not the actual code but it's enough to see the point. Every time the File_Created event is triggered, it creates a new thread and thus I'm unable to interact with the UI from that event, it throws an exception.
Everything else in my program works except the logging part but it's kinda annoying.
Is there a way around it?
Thanks, Arik