views:

29

answers:

1

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.

A: 

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.

JaredPar
sweet, thanks so much.had to turn off option strict too to avoid a narrowing implict type conversion.
Phil Sayers
for reference, listener.Handle looks like this:Public Interface IListener(Of T)Sub Handle(ByVal message As T)End Interface
Phil Sayers