如何使用ISynchronizeInvoke接口? [英] How to Use ISynchronizeInvoke interface?

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

问题描述

什么是 ISynchronizeInvoke 的工作程序?

如何使用它在C#中?

How to work with it in C#?

推荐答案

这基本上描述了一个办法,推动线程之间的工作;推动工作的一个项目到另一个线程,使用调用(同​​步)或的BeginInvoke (异步 - 理想的呼唤后来 EndInvoke会)。同样, InvokeRequired 是用来问我需要做到这一点?或者我可以执行的工作我自己?

This basically describes a way to push work between threads; to push an item of work onto the other thread, use either Invoke (synchronous) or BeginInvoke (asynchronous - ideally calling EndInvoke later). Likewise, InvokeRequired is used to ask "do I need to do this? or can I execute the work myself?".

此接口的最常见的用途是在Windows的形式,它是如何工作推到UI线程的一部分;当然你也可以使用 Control.Invoke / Control.BeginInvoke 一样,但窗体控件实现该接口允许抽象 - 所以下游代码并不需要把自己绑在窗户的形式。在表格的情况下, InvokeRequired 表示我是在UI线程?

The most common use of this interface is in windows-forms, where it is part of how to push work onto the UI thread; you can of course use Control.Invoke / Control.BeginInvoke equally, but forms controls implement this interface to allow abstraction - so downstream code doesn't need to tie itself to windows forms. In the case of forms, InvokeRequired means "am I the UI thread?".

在现实中,我不能肯定它是常见的直接使用它。 ,这是比较常见的处理的UI事件,并使用最合适的地方机制UI处理线程切换

In reality, I'm not sure it is that common to use it directly. It is more common to handle events on the UI, and have the UI handle thread-switching using the most appropriate local mechanism.

典型用法:

obj.Invoke((MethodInvoker) SomeMethod);



它执行(通过一个代表)的someMethod OBJ 管理​​线程(它实现了接口)。

which executes (via a delegate) SomeMethod on the thread managed by obj (which implements the interface).

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

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