如何使用的BeginInvoke C# [英] How to use BeginInvoke C#

查看:869
本文介绍了如何使用的BeginInvoke C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能解释一下这对我好吗:

Could you explain this for me please:

someformobj.BeginInvoke((Action)(() =>
{
    someformobj.listBox1.SelectedIndex = 0;
}));



你能告诉我怎么可以使用的BeginInvoke 到底是什么?
是什么动作键入?
为何会有空白的括号()
和这是什么意思 =>

Could you tell me how can I use begininvoke exactly? What is Action type? Why there is blank brackets ()? And what does this mean =>?

推荐答案

动作 是一个类型代表由.NET Framework提供。在动作点,不带参数的方法,并没有返回值。

Action is a Type of Delegate provided by the .NET framework. The Action points to a method with no parameters and does not return a value.

()=> lambda表达式语法。 Lambda表达式是类型代表不是。调用需要代表所以动作可用于包装lambda表达式,并提供预期的类型的invoke()

() => is lambda expression syntax. Lambda expressions are not of Type Delegate. Invoke requires Delegate so Action can be used to wrap the lambda expression and provide the expected Type to Invoke()

调用的原因说动作来创建控件的窗口句柄的线程上执行。更改线程往往是必要的,以避免例外。例如,如果一个人试图设置在 RTF 属性的RichTextBox 当调用是必要的,而无需先调用调用,那么跨线程操作无效将引发异常。在调用调用前检查 Control.InvokeRequired

Invoke causes said Action to execute on the thread that created the Control's window handle. Changing threads is often necessary to avoid Exceptions. For example, if one tries to set the Rtf property on a RichTextBox when an Invoke is necessary, without first calling Invoke, then a Cross-thread operation not valid exception will be thrown. Check Control.InvokeRequired before calling Invoke.

的BeginInvoke 调用的异步版本。异步意味着线程不会阻塞调用者,而不是被阻塞同步调用。

BeginInvoke is the Asynchronous version of Invoke. Asynchronous means the thread will not block the caller as opposed to a synchronous call which is blocking.

这篇关于如何使用的BeginInvoke C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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