【发布时间】:2011-01-02 10:54:45
【问题描述】:
伪代码:
form1
{
int i;
label1;
Add()
{
i++;
label1 = i.ToString(); //#ErrorLine
}
backgroundworker worker;
worker_DoWork()
{
FileGuard guard = new FileGuard();
guard.FileKilled += guard.KillH(Add);
guard.StarGuarding(); //there is system watcher inside
//this guard and some processing code
//that will fire event FileKilled();
}
}
调用 StartGuarding() worker 后将完成 但是当触发 FileKilled 事件时,我在 #ErrorLine
行出现了这个错误跨线程操作无效:控件“form1”从创建它的线程以外的线程访问。
【问题讨论】:
标签: c# .net multithreading event-handling backgroundworker