|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Can someone please translate this to VB.Net{ 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(); } }
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(); > } > } > > (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 -- Show quoteHide quoteDavid 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(); > } > } > > 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(); >> } >> } >> >>
calling math functions at run time
regarding .net help Help reading control.location value back form text file simple format question Getting IP Address of the ACTIVE network card DataGridView conversion problems Good book for an absolute beginner on VB.net or 2005 with databases newbie: foundfile attributes? (filesize, saved date, etc.) help readin text file need help with 1 line of code now! |
|||||||||||||||||||||||