我正在执行以下代码:
grid.Invoke(New MethodInvoker(AddressOf RefreshDataSource))
获得InvalidOperationException
例外。
消息:在创建窗口句柄之前,无法在控件上调用Invoke或BeginInvoke。
堆栈追踪:
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.Invoke(Delegate method)
at DataForm.BindData() in D:\Proj\DataForm.vb:line 380
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
答案 0 :(得分:0)
将调用从load事件更改为form.shown事件,以确保首先创建控件
答案 1 :(得分:0)
.modalBox
答案 2 :(得分:0)
在调用调用方法while (!this.IsHandleCreated)
System.Threading.Thread.Sleep(100)