SynchronizationContext.Send,什么是SendOrPostCallback?
VB.NET 2010,.NET 4
这可能是一个愚蠢的问题,但我想知道 SendOrPostCallback
委托有什么特别之处,它是 WindowsFormsSynchronizationContext
中的第一个参数 < code>Send 和 Post
方法?换句话说,我可以执行以下操作:
SyncContext.Send(Sub() ..some work.., Nothing)
并且有效(SyncContext
是一个 WindowsFormsSynchronizationContext
对象)。为什么最好这样做:
Dim blah As Threading.SendOrPostCallback = Sub() ..some work..
SyncContext.Send(blah, Nothing)
?
更新:确认汉斯的回答,我更新问题:如果没有区别,为什么要定义 SendOrPostCallback
?它有什么特别的地方还是只是一个别名?也许我只是没有得到更基本的东西。
VB.NET 2010, .NET 4
This might be a dumb question but I'm wondering what is special about the SendOrPostCallback
delegate that is the first argument in WindowsFormsSynchronizationContext
's Send
and Post
methods? In other words, I can do the following:
SyncContext.Send(Sub() ..some work.., Nothing)
And that works (SyncContext
is a WindowsFormsSynchronizationContext
object). Why might it be preferable to do:
Dim blah As Threading.SendOrPostCallback = Sub() ..some work..
SyncContext.Send(blah, Nothing)
?
Update: Acknowledging Hans' answer, I update the question: If there is no difference, why is SendOrPostCallback
defined? Is there something special about it or is it just an alias? Perhaps I'm just not getting something more fundamental.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没什么,它只是一个像其他代表一样的代表。片段之间没有逻辑差异,JIT 编译器生成相同的代码。选择您喜欢的风格。
Nothing, it is just a delegate like any other. There's no logical difference between the snippets, the JIT compiler generates the same code. Pick the style you prefer.