-1

我正在执行以下代码:

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)
4

3 回答 3

0

将调用从 load 事件更改为 form.shown 事件,以确保首先创建了控件

于 2013-05-14T10:13:56.633 回答
0
if (!this.IsHandleCreated)
    this.CreateControl();

this.Invoke((MethodInvoker)delegate
    {
       //do so      
    });
于 2017-08-30T20:49:21.170 回答
0

在调用调用方法之前添加它 while (!this.IsHandleCreated) System.Threading.Thread.Sleep(100)

于 2019-03-18T15:47:49.013 回答