Control.Invoke(deligate)和Normal Method Call之间有什么区别。 [英] What is the difference between Control.Invoke(deligate) and Normal Method Call.

查看:120
本文介绍了Control.Invoke(deligate)和Normal Method Call之间有什么区别。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Control.Invoke(deligate)和Normal Method Call之间有什么区别。


我们需要在哪些senarios中调用Control.invoke(deligate)来调用方法。 / p>

如果有人知道请向我解释。


谢谢。

解决方案

Control.Invoke用于同步。


只能从创建的线程访问Control实例的任何实例成员。您可以使用Control.Invoke在Control的线程上执行一个方法(使用委托参数)。


您经常会在Control.InvokeRequired属性附近找到对Control.Invoke的引用,当从其他线程调用get访问器然后创建Control时,返回true。

 
void backGroundworker_ProgressChanged( object sender,ProgressChangedEventArgs e)
{
if this .InvokeRequired)
{
this .Invoke(...)
}
}


What is the difference between Control.Invoke(deligate) and Normal Method Call.

In which senarios we need Control.invoke(deligate) to call a method.

If any one knows please explain to me.

thank you.

解决方案

Control.Invoke is used for synchronization.

Any instance member of a Control instance can only be accessed from the thread is was created on. You can use Control.Invoke to execute a method (using the delegate param) on the Control's thread.

You will often find references to Control.Invoke in close proximity to the Control.InvokeRequired property, which returns true when the get accessor is invoked from a different thread then the one the Control was created on.

void backGroundworker_ProgressChanged( object sender, ProgressChangedEventArgs e )
    {
       if(this.InvokeRequired)
       {
         this.Invoke(...)
       }
    }


这篇关于Control.Invoke(deligate)和Normal Method Call之间有什么区别。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆