c# - Invoke or BeginInvoke cannot be called Error -
i have program used clients world wide. check error logs , quite few seem having exception (listed below) thrown can't figure out or trace.
i have invokes protected invokerequired. i'm thinking, if should use use if (handlecreated) instead.
i not sure or when exception thrown.
in start up, after initializecomponent();, have tasks require access controls such datagridview. however, said, try protect them invokerequired. not sure if that's place causing problem.
what suggestions perform try , trace problem?
anyway, exception:
system.invalidoperationexception: invoke or begininvoke cannot called on control until window handle has been created. @ system.windows.forms.control.waitforwaithandle(waithandle waithandle) @ system.windows.forms.control.marshaledinvoke(control caller, delegate method, object[] args, boolean synchronous) @ system.windows.forms.control.invoke(delegate method, object[] args) @ system.windows.forms.control.invoke(delegate method) @ ..() @ ..() @ system.threading.threadhelper.threadstart_context(object state) @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state) @ system.threading.threadhelper.threadstart()
no, cannot happen if use invokerequired. true when handle valid. simple avoid anyway, don't subscribe event or start thread until load event fires.
this crash occurs when form closes. cannot see in stack trace because happens on thread. there's race condition in invokerequired + begin/invoke(). invokerequired might return true , microsecond later form closes. begin/invoke call fail exception.
this not race can solve. must ensure thread can no longer call begininvoke() before allowing form close. invariably means have prevent form closing. background info in this answer.
Comments
Post a Comment