调用control.BeginInvoke时实际上会发生什么? [英] What happen actually when control.BeginInvoke is called?

查看:177
本文介绍了调用control.BeginInvoke时实际上会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

Control.BeginInvoke(Delegate):在创建控件的基础句柄的线程上异步地"执行指定的委托" ".该委托被异步调用.您可以从任何线程调用此方法,"甚至是拥有控件句柄的线程."

用粗体引用上述文本,如果我们调用主线程中的任何控件的BeginInvoke方法(正在忙于执行其他一些任务)会发生什么呢?

会有两个线程吗?

还是对BeginInvoke的调用将等待主线程完成其执行任务?如果是这样,那么如果主线程的执行任务非常耗时,则UI可能会进入非响应状态.

Hello,

Control.BeginInvoke(Delegate) : Executes the specified delegate "asynchronously on the thread" that the control''s underlying handle was created on. The delegate is called asynchronously. You can call this method from any thread, "even the thread that owns the control''s handle."

Referring the above texts in bold, what will happen actually if we call BeginInvoke method of any control in the Main Thread ( which is busy executing some other tasks)?

Will there be two threads?

Or this call to BeginInvoke will wait for Main thread to complete its executing task? if so, then UI may go into nonresponding state if the executing task of Main Thread is quite time consuming.

推荐答案

已经有两个线程-一个是应用程序所在的线程继续前进,然后您开始自己动手. BeginInvoke调用只是执行.Net所需的操作,以便安全地从其他线程修改控件.

此主题是在此处进行广泛回答的方法,因为该站点的这一部分不利于长线程.请在C#论坛中提出相同的问题,以便进行适当的讨论.
There are already two threads - the one the application is running on, and the one you started yourself. The BeginInvoke call simply does what .Net needs to have done in order to safely modify a control from a different thread.

This topic is way to extensive to answer here because this part of the site is not conducive to long threads. Please ask the same question in the C# forum so a proper discussion can be conducted.


控制思想.BeginInvoke作为排队机制.它将委托添加到作业队列中,该队列将在将来某个时候由拥有控件句柄的线程执行.

链接中的说明可能会有所帮助.
http://www.drdobbs.com/184429353 [
Think of Control.BeginInvoke as a queueing mechanism. It adds the delegate to a job queue which will be executed at some point in the future by the thread that owns the control''s handle.

The explanation in the link may help.
http://www.drdobbs.com/184429353[^]

Alan.


这篇关于调用control.BeginInvoke时实际上会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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