Home All Groups Group Topic Archive Search About

Can someone please translate this to VB.Net

Author
25 Nov 2006 4:56 PM
Mike
public class Broadcaster: MarshalByRefObject, IBroadcaster
    {

        public event General.MessageArrivedHandler MessageArrived;

        public void BroadcastMessage(string msg) {
            Console.WriteLine("Will broadcast message: {0}", msg);
            SafeInvokeEvent(msg);
        }

        private void SafeInvokeEvent(String msg) {
            // call the delegates manually to remove them if they aren't
            // active anymore.

            if (MessageArrived == null) {
                Console.WriteLine("No listeners");
            } else {
                Console.WriteLine("Number of Listeners:
{0}",MessageArrived.GetInvocationList().Length);
                MessageArrivedHandler mah=null;

                foreach (Delegate del in MessageArrived.GetInvocationList()) {
                    try {
                        mah = (MessageArrivedHandler) del;
                        mah(msg);
                    } catch (Exception e) {
                        Console.WriteLine("Exception occured, will remove Delegate");
                        MessageArrived -= mah;
                    }
                }
            }
        }

        public override object InitializeLifetimeService() {
            // this object has to live "forever"
            return null;
        }
    }


    class ServerStartup
    {
        static void Main(string[] args)
        {
            String filename = "server.exe.config";
            RemotingConfiguration.Configure(filename);

            Console.WriteLine ("Server started, press <return> to exit.");
            Console.ReadLine();
        }
    }

Author
25 Nov 2006 7:32 PM
Mr Struggler
http://authors.aspalliance.com/aldotnet/examples/translate.aspx


Show quote Hide quote
"Mike" <jm***@yahoo.com> wrote in message
news:EFBD91F9-1DFE-4170-BC63-D1E5FFA0102B@microsoft.com...
>
> public class Broadcaster: MarshalByRefObject, IBroadcaster
> {
>
> public event General.MessageArrivedHandler MessageArrived;
>
> public void BroadcastMessage(string msg) {
> Console.WriteLine("Will broadcast message: {0}", msg);
> SafeInvokeEvent(msg);
> }
>
> private void SafeInvokeEvent(String msg) {
> // call the delegates manually to remove them if they aren't
> // active anymore.
>
> if (MessageArrived == null) {
> Console.WriteLine("No listeners");
> } else {
> Console.WriteLine("Number of Listeners:
> {0}",MessageArrived.GetInvocationList().Length);
> MessageArrivedHandler mah=null;
>
> foreach (Delegate del in MessageArrived.GetInvocationList()) {
> try {
> mah = (MessageArrivedHandler) del;
> mah(msg);
> } catch (Exception e) {
> Console.WriteLine("Exception occured, will remove Delegate");
> MessageArrived -= mah;
> }
> }
> }
> }
>
> public override object InitializeLifetimeService() {
> // this object has to live "forever"
> return null;
> }
> }
>
>
> class ServerStartup
> {
> static void Main(string[] args)
> {
> String filename = "server.exe.config";
> RemotingConfiguration.Configure(filename);
>
> Console.WriteLine ("Server started, press <return> to exit.");
> Console.ReadLine();
> }
> }
>
>
Author
26 Nov 2006 1:53 AM
David Anton
(via Instant VB - note that there is no IBroadcaster defined in the original
code or the .NET Framework, so you'll have to add the "Implements" tags to
the methods yourself)

    Public Class Broadcaster
        Inherits MarshalByRefObject
        Implements IBroadcaster

        Public Event MessageArrived As General.MessageArrivedHandler

        Public Sub BroadcastMessage(ByVal msg As String)
            Console.WriteLine("Will broadcast message: {0}", msg)
            SafeInvokeEvent(msg)
        End Sub

        Private Sub SafeInvokeEvent(ByVal msg As String)
            ' call the delegates manually to remove them if they aren't
            ' active anymore.

            If MessageArrivedEvent Is Nothing Then
                Console.WriteLine("No listeners")
            Else
                Console.WriteLine("Number of Listeners:
{0}",MessageArrivedEvent.GetInvocationList().Length)
                Dim mah As MessageArrivedHandler=Nothing

                For Each del As System.Delegate In MessageArrivedEvent.GetInvocationList()
                    Try
                        mah = CType(del, MessageArrivedHandler)
                        mah(msg)
                    Catch e As Exception
                        Console.WriteLine("Exception occured, will remove Delegate")
                        RemoveHandler MessageArrived, mah
                    End Try
                Next del
            End If
        End Sub

        Public Overrides Function InitializeLifetimeService() As Object
            ' this object has to live "forever"
            Return Nothing
        End Function
    End Class


    Friend Class ServerStartup
        Shared Sub Main(ByVal args As String())
            Dim filename As String = "server.exe.config"
            RemotingConfiguration.Configure(filename)

            Console.WriteLine ("Server started, press <return> to exit.")
            Console.ReadLine()
        End Sub
    End Class

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter


Show quoteHide quote
"Mike" wrote:

>
>     public class Broadcaster: MarshalByRefObject, IBroadcaster
>     {
>
>         public event General.MessageArrivedHandler MessageArrived;
>
>         public void BroadcastMessage(string msg) {
>             Console.WriteLine("Will broadcast message: {0}", msg);
>             SafeInvokeEvent(msg);
>         }
>
>         private void SafeInvokeEvent(String msg) {
>             // call the delegates manually to remove them if they aren't
>             // active anymore.
>
>             if (MessageArrived == null) {
>                 Console.WriteLine("No listeners");
>             } else {
>                 Console.WriteLine("Number of Listeners:
> {0}",MessageArrived.GetInvocationList().Length);
>                 MessageArrivedHandler mah=null;
>
>                 foreach (Delegate del in MessageArrived.GetInvocationList()) {
>                     try {
>                         mah = (MessageArrivedHandler) del;
>                         mah(msg);
>                     } catch (Exception e) {
>                         Console.WriteLine("Exception occured, will remove Delegate");
>                         MessageArrived -= mah;
>                     }
>                 }
>             }
>         }
>
>         public override object InitializeLifetimeService() {
>             // this object has to live "forever"
>             return null;
>         }
>     }
>
>
>     class ServerStartup
>     {
>         static void Main(string[] args)
>         {
>             String filename = "server.exe.config";
>             RemotingConfiguration.Configure(filename);
>
>             Console.WriteLine ("Server started, press <return> to exit.");
>             Console.ReadLine();
>         }
>     }

>
Author
29 Nov 2006 1:42 PM
Mike
Thanks David!

Show quoteHide quote
"David Anton" <DavidAn***@discussions.microsoft.com> wrote in message
news:24E110EA-4D3D-462C-AECE-A291AE77B83D@microsoft.com...
> (via Instant VB - note that there is no IBroadcaster defined in the
> original
> code or the .NET Framework, so you'll have to add the "Implements" tags to
> the methods yourself)
>
> Public Class Broadcaster
> Inherits MarshalByRefObject
> Implements IBroadcaster
>
> Public Event MessageArrived As General.MessageArrivedHandler
>
> Public Sub BroadcastMessage(ByVal msg As String)
> Console.WriteLine("Will broadcast message: {0}", msg)
> SafeInvokeEvent(msg)
> End Sub
>
> Private Sub SafeInvokeEvent(ByVal msg As String)
> ' call the delegates manually to remove them if they aren't
> ' active anymore.
>
> If MessageArrivedEvent Is Nothing Then
> Console.WriteLine("No listeners")
> Else
> Console.WriteLine("Number of Listeners:
> {0}",MessageArrivedEvent.GetInvocationList().Length)
> Dim mah As MessageArrivedHandler=Nothing
>
> For Each del As System.Delegate In MessageArrivedEvent.GetInvocationList()
> Try
> mah = CType(del, MessageArrivedHandler)
> mah(msg)
> Catch e As Exception
> Console.WriteLine("Exception occured, will remove Delegate")
> RemoveHandler MessageArrived, mah
> End Try
> Next del
> End If
> End Sub
>
> Public Overrides Function InitializeLifetimeService() As Object
> ' this object has to live "forever"
> Return Nothing
> End Function
> End Class
>
>
> Friend Class ServerStartup
> Shared Sub Main(ByVal args As String())
> Dim filename As String = "server.exe.config"
> RemotingConfiguration.Configure(filename)
>
> Console.WriteLine ("Server started, press <return> to exit.")
> Console.ReadLine()
> End Sub
> End Class
>
> --
> David Anton
> www.tangiblesoftwaresolutions.com
> Instant C#: VB to C# converter
> Instant VB: C# to VB converter
> Instant C++: C#/VB to C++ converter
> Instant Python: VB to Python converter
>
>
> "Mike" wrote:
>
>>
>> public class Broadcaster: MarshalByRefObject, IBroadcaster
>> {
>>
>> public event General.MessageArrivedHandler MessageArrived;
>>
>> public void BroadcastMessage(string msg) {
>> Console.WriteLine("Will broadcast message: {0}", msg);
>> SafeInvokeEvent(msg);
>> }
>>
>> private void SafeInvokeEvent(String msg) {
>> // call the delegates manually to remove them if they aren't
>> // active anymore.
>>
>> if (MessageArrived == null) {
>> Console.WriteLine("No listeners");
>> } else {
>> Console.WriteLine("Number of Listeners:
>> {0}",MessageArrived.GetInvocationList().Length);
>> MessageArrivedHandler mah=null;
>>
>> foreach (Delegate del in MessageArrived.GetInvocationList()) {
>> try {
>> mah = (MessageArrivedHandler) del;
>> mah(msg);
>> } catch (Exception e) {
>> Console.WriteLine("Exception occured, will remove Delegate");
>> MessageArrived -= mah;
>> }
>> }
>> }
>> }
>>
>> public override object InitializeLifetimeService() {
>> // this object has to live "forever"
>> return null;
>> }
>> }
>>
>>
>> class ServerStartup
>> {
>> static void Main(string[] args)
>> {
>> String filename = "server.exe.config";
>> RemotingConfiguration.Configure(filename);
>>
>> Console.WriteLine ("Server started, press <return> to exit.");
>> Console.ReadLine();
>> }
>> }
>>
>>