use invoke和syncingcontext.Post对象之间有什么区别? [英] What are difference between use invoke and synchronizationcontext.Post object?

查看:96
本文介绍了use invoke和syncingcontext.Post对象之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我收到与线程上下文相关的异常时,我使用委托函数并调用此委托函数.必须从其他线程进行使用控制.但是我刚刚了解到可以使用 SynchronizationContext.Post()函数,并且可以在此方法中调用我的委托.但是我不确定哪个更好?或这些方法之间有什么区别.

When I received an exception that is related with thread context, I use delegate function and I invoke this delegate function. It is necessary for use control from an other thread. But I've just learned that I can use SynchronizationContext.Post() function and I can call my delegate in this method. But I'm not sure which one is better? or What are difference between these methods.

非常感谢.

推荐答案

是同一回事,SynchronizationContext.Post()调用BeginInvoke(),Send()调用Invoke().

It is the same thing, SynchronizationContext.Post() calls BeginInvoke() and Send() calls Invoke().

SynchronizationContext的关键属性是它有多个实现.重要的是WindowsFormsSynchronizationContext,它使用Control.Begin/Invoke和DispatcherSynchronizationContext,它使用Dispatcher.Begin/Invoke.还有其他一些ASP.NET,Windows Store(又名WinRT,又名Universal)应用程序,COM +托管的进程外服务器等.

The key property of SynchronizationContext is that there is more than one implementation of it. Important ones are WindowsFormsSynchronizationContext, it uses Control.Begin/Invoke and DispatcherSynchronizationContext, it uses Dispatcher.Begin/Invoke. There are others for ASP.NET, Windows Store (aka WinRT, aka Universal) apps, out-of-process servers that are COM+ hosted, etcetera.

额外的间接级别有助于避免依赖于所调用的 specific 方法.对于任何课程类库都很重要.

The extra level of indirection helps avoid taking a dependency on the specific method that invokes. Important for any class library of course.

这篇关于use invoke和syncingcontext.Post对象之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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