Results 1 to 3 of 3

Thread: [RESOLVED] Translate from C# to VB

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Resolved [RESOLVED] Translate from C# to VB

    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 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?

    Code:
    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);
            }
        });
    }

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: Translate from C# to VB

    I think I got it..... is this correct?

    Code:
    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

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Translate from C# to VB

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width