开发者

Translating EventAggregators usage of SynchronizationContext to VB.Net

Working with开发者_Go百科 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜