c# - FileSystemWatcher - Log Results in UI -


i building program supposed watch project folder change in source code , send these changes somewhere , in process, log files changed in windows form textbox.

the code looks 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, not actual code it's enough see point. every time file_created event triggered, creates new thread , i'm unable interact ui event, throws exception.

everything else in program works except logging part it's kinda annoying.

is there way around it?

thanks, arik

if want update ui other thread need use:

dispatcher.invoke(new action(() => {    logs.text += name + environment.newline;  })); 

i hope can you


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -