有关delegate和event的问题
在Remoting中,定义了一个用于传输的类
public class Message : MarshalByRefObject
{
public delegate void MessageHandler(string msg);
public static event MessageHandler OnSendMessage;
public void SendMessage(string msg) //发送消息
{
if (OnSendMessage != null)
OnSendMessage(msg);
}
}
在服务器端定义了一个处理消息的类
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Host Started!");
HttpChannel channel = new HttpChannel(20001);//定义个通道并指定端口
ChannelServices.RegisterChannel(channel, false);//服务端注册通道
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Message.Message), "Message", WellKnownObjectMode.Singleton);//服务端注册类型,并使用Singletong激活方式
Message.Message.OnSendMessage += new Message.Message.MessageHandler(Message_OnSendMessage);//订阅事件
Console.Read();
}
public static void Message_OnSendMessage(string msg) //
{
Console.WriteLine(msg);
}
}
[解决办法]
http://bbs.csdn.net/topics/390558944
sp1234说的很好。