Win form Control.Invoke 探索

Control.Invoke用于在子线程中,把执行UI线程的代码。怎么做到的呢?
分析一下源码。redgate反编译,看到 
Control.Invoke源码如下:

public Delegate method, params MultithreadSafeCallScope())
    {
        return this.MarshaledInvoke(this, method, args, true);
    }
}

private Control caller, object[] args, int num;
    if (!this.InvalidOperationException(GetString("ErrorNoMarshalingThread"));
    }
    if (((Properties.PropActiveXImpl)) != null)
    {
        UnmanagedCode.bool flag = false;
    if ((GetWindowThreadProcessId(new Handle), out num) == GetCurrentThreadId()) && synchronous)
    {
        flag = true;
    }
    ExecutionContext.ThreadMethodEntry entry = new Control control = this;
    lock (control)
    {
        if (this.threadCallbackList = new Queue threadCallbackList = this.threadCallbackMessage == 0)
        {
            SafeNativeMethods.Application.threadCallbackList.InvokeMarshaledCallbacks();
    }
    else
    {
        PostMessage(new Handle), IntPtr.IntPtr.IsCompleted)
    {
        this.AsyncWaitHandle);
    }
    if (entry.exception;
    }
    return entry.<a title="" object="" system.windows.forms.control+threadmethodentry.retval;"="" href="http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://System.Windows.Forms:4.0.0.0:b77a5c561934e089/System.Windows.Forms.Control.ThreadMethodEntry/retVal:Object" _xhe_href="http://127.0.0.1/roeder/dotnet/Default.aspx?Target=code://System.Windows.Forms:4.0.0.0:b77a5c561934e089/System.Windows.Forms.Control.ThreadMethodEntry/retVal:Object">retVal;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值