(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 MarshalByRefObj ect
Implements IBroadcaster
Public Event MessageArrived As General.Message ArrivedHandler
Public Sub BroadcastMessag e(ByVal msg As String)
Console.WriteLi ne("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 MessageArrivedE vent Is Nothing Then
Console.WriteLi ne("No listeners")
Else
Console.WriteLi ne("Number of Listeners:
{0}",MessageArr ivedEvent.GetIn vocationList(). Length)
Dim mah As MessageArrivedH andler=Nothing
For Each del As System.Delegate In MessageArrivedE vent.GetInvocat ionList()
Try
mah = CType(del, MessageArrivedH andler)
mah(msg)
Catch e As Exception
Console.WriteLi ne("Exception occured, will remove Delegate")
RemoveHandler MessageArrived, mah
End Try
Next del
End If
End Sub
Public Overrides Function InitializeLifet imeService() 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.con fig"
RemotingConfigu ration.Configur e(filename)
Console.WriteLi ne ("Server started, press <returnto exit.")
Console.ReadLin e()
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: MarshalByRefObj ect, IBroadcaster
{
public event General.Message ArrivedHandler MessageArrived;
public void BroadcastMessag e(string msg) {
Console.WriteLi ne("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.WriteLi ne("No listeners");
} else {
Console.WriteLi ne("Number of Listeners:
{0}",MessageArr ived.GetInvocat ionList().Lengt h);
MessageArrivedH andler mah=null;
foreach (Delegate del in MessageArrived. GetInvocationLi st()) {
try {
mah = (MessageArrived Handler) del;
mah(msg);
} catch (Exception e) {
Console.WriteLi ne("Exception occured, will remove Delegate");
MessageArrived -= mah;
}
}
}
}
public override object InitializeLifet imeService() {
// this object has to live "forever"
return null;
}
}
class ServerStartup
{
static void Main(string[] args)
{
String filename = "server.exe.con fig";
RemotingConfigu ration.Configur e(filename);
Console.WriteLi ne ("Server started, press <returnto exit.");
Console.ReadLin e();
}
}