PDA

Click to See Complete Forum and Search --> : [RESOLVED] Translate from C# to VB


Hamish
Feb 20th, 2009, 10:16 AM
I think there should be a seperate area for this kind of questions. :)
I'm trying to get the hang of WCF as you probably know from my other posts around here. I found a simple example (http://idunno.org/archive/2008/05/29/wcf-callbacks-a-beginners-guide.aspx) of WCF callbacks, and I'm trying to understand it by reproducing it. As usual though, the sample is in C#, and although I'm starting to get better at it, I still don't get it all the time.
So here's another piece of C#.... could anyone explain or translate it (will serve as explanation enough I hope) for me?


public void AddMessage(string message)
{
subscribers.ForEach(delegate(IMessageCallback callback)
{
if (((ICommunicationObject)callback).State == CommunicationState.Opened)
{
callback.OnMessageAdded(message, DateTime.Now);
}
else
{
subscribers.Remove(callback);
}
});
}

Hamish
Feb 20th, 2009, 10:39 AM
I think I got it..... is this correct?


Public Sub AddMessage(message As String)
For Each callback As IMessageCallback In subscribers
If DirectCast(callback, ICommunicationsObject).State = CommunicationState.Opened Then
callback.OnMessageAdded(message, DateTime.Now)
Else
subscribers.Remove(callback)
End If
Next
End Sub

techgnome
Feb 20th, 2009, 12:44 PM
in short it looks like it's looping through a list of potential delegates, if the state is opened, the message gets sent through... if not, then it is removed from the collection.

-tg