.Net Remote ipcchannel und events



  • Hallo,

    ich möchte gerne events auslösen. Beim Server kommt das Event an, aber nicht
    beim Client. Warum nicht, muss ich da noch etwas beachten?
    Hier der Code dazu:

    server

    static void Main(string[] args)
            {
                IpcChannel channel = new IpcChannel("localhost:32600");
                ChannelServices.RegisterChannel(channel,true);
                GethLib.serverMethods.critmsg += new GethLib.serverMethods.critmsgHandler(serverMethods_critmsg);
                Console.WriteLine("The name of the channel is {0}.",
                    channel.ChannelName);
    
                Console.WriteLine("The priority of the channel is {0}.",
                    channel.ChannelPriority);
    
                System.Runtime.Remoting.Channels.ChannelDataStore channelData =
                            (System.Runtime.Remoting.Channels.ChannelDataStore)
                channel.ChannelData;
                foreach (string uri in channelData.ChannelUris)
                {
                    Console.WriteLine("The channel URI is {0}.", uri);
                }
    
                System.Runtime.Remoting.RemotingConfiguration.
                    RegisterWellKnownServiceType(
                        typeof(GethLib.serverMethods), "serverMethods",
                        System.Runtime.Remoting.WellKnownObjectMode.Singleton);
    
                string[] urls = channel.GetUrlsForUri("serverMethods");
                if (urls.Length > 0)
                {
                    string objectUrl = urls[0];
                    string objectUri;
                    string channelUri = channel.Parse(objectUrl, out objectUri);
                    Console.WriteLine("The object URI is {0}.", objectUri);
                    Console.WriteLine("The channel URI is {0}.", channelUri);
                    Console.WriteLine("The object URL is {0}.", objectUrl);
                }
    
                Console.WriteLine("Press ENTER to exit the server.");
                Console.ReadLine();
                Console.WriteLine("The server is exiting.");
            }
    
            static void serverMethods_critmsg(string CritMsg)
            {
                Console.WriteLine(CritMsg);
            }
        }
    

    servermethods:

    public class serverMethods:MarshalByRefObject
        {
            private int msg;
            private string xCritmsg = "Kritischer Wert erreicht!";
    
            public delegate void critmsgHandler(string CritMsg);
            public static event critmsgHandler critmsg = null;
            public int Msg
            {
                get 
                {
                    if (msg > 5)
                    {
                        if (critmsg != null)
                        {
                            critmsg(xCritmsg);
                        }
                    }
                    return (msg++); 
                }
            }
        }
    

    Client:

    class Program
        {
            static void Main(string[] args)
            {
                IpcClientChannel clientChannel = new IpcClientChannel();
                ChannelServices.RegisterChannel(clientChannel,true);
    
                RemotingConfiguration.RegisterWellKnownClientType(typeof(GethLib.serverMethods), "ipc://localhost:32600/serverMethods");
                GethLib.serverMethods sm = null;
    
                for (int i = 0; i < 10; i++)
                {
                    sm = new GethLib.serverMethods();
                    Console.WriteLine(sm.Msg);
                }
                GethLib.serverMethods.critmsg += new GethLib.serverMethods.critmsgHandler(serverMethods_critmsg);
            }
    
            static void serverMethods_critmsg(string CritMsg)
            {
                Console.WriteLine(CritMsg);
            }
    
        }
    

    Danke


Anmelden zum Antworten