将 SynchronizationContext 的 EventAggregators 使用转换为 VB.Net

发布于 2024-09-02 11:09:59 字数 621 浏览 3 评论 0原文

使用相当大的 VB.Net 后台 winforms 应用程序。 100 万+ LOC。 大泥球,90% 的代码都在 Forms & 中。其他 UI 控件。

随着时间的推移,慢慢引入更好的架构。资源允许,我们一直在使用 Jeremy Miller 的 EventAggrgator 的想法。

最初我去掉了 SynchronizationContext 的使用。现在我正试图将它引入回来,并且我正在努力将 lamda 内容从 c# 转换为 vb.net。

具体来说,这行 c#

_context.Send(delegate { receiver.Handle(subject); }, null);

这是我迄今为止的 vb.net:

_context.Send(New SendOrPostCallback(AddressOf listener.Handle(message)), Nothing)

我收到的错误是

listener.Handle(message) <-- AddressOf 操作数必须是方法的名称。

我确信我错过了一些简单的东西,但在盯着这个两天之后,我迷失了。

Working with a fairly large VB.Net back office winforms application. 1 million+ LOC.
Big ball of mud, 90% of all code is in Forms & other UI controls.

Slowly introducing better architecture as time & recources allows, We've been using ideas from the EventAggrgator by Jeremy Miller.

http://codebetter.com/blogs/jeremy.miller/archive/2008/01/11/build-your-own-cab-extensible-pub-sub-event-aggregator-with-generics.aspx

Initially I stripped out the usage of SynchronizationContext. Now I'm trying to introduce it back, and I'm struggling with the translation of the lamda stuff from c# to vb.net.

Specifically this line of c#

_context.Send(delegate { receiver.Handle(subject); }, null);

This is the vb.net I have so far:

_context.Send(New SendOrPostCallback(AddressOf listener.Handle(message)), Nothing)

The error I'm getting is

listener.Handle(message) <-- AddressOf operand must be the name of a method.

I'm sure I'm missing something simple, but after staring at this for 2 days, I'm lost.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事还在继续 2024-09-09 11:09:59

尝试以下方法

_context.Send(New SendOrPostCallback(AddressOf listener.Handle), message)

问题是您正在尝试转换 C# 委托,而 VB 直到 VB9 才支持这些委托。这种委托风格,即 void 返回,直到 VB10 才真正得到支持。

最好的翻译是使用直接代表。根据签名,上述内容应该有效。如果没有,请发布listener.Handle的签名,以便我们给出更好的答案。

Try the following

_context.Send(New SendOrPostCallback(AddressOf listener.Handle), message)

The problem is you're trying to translate C# delegates which aren't supported in VB until VB9. This style of delegate, void returning, is not actually supported until VB10.

The best translation is to use straight delegates instead. Depending on the signature the above should work. if not, please post the signature for listener.Handle so we can give a better answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文