zoukankan      html  css  js  c++  java
  • WCF 中 IPC 跨进程访问对象

    直接上代码:

    服务端:
      private
    static string ServerChannelId = $"ScanSnapHome-{Environment.UserName}";   var serverChannel = IpcServerChannelUtil.GetIpcServerChannelInstance(ServerChannelId);   ChannelServices.RegisterChannel(serverChannel, true);   sharingData = new SharingData();   sharingData.OnNotify += new SharingData.CallEventHandler(OnNotify); // OnNotify 回调函数,就不上传了   RemotingServices.Marshal(sharingData, "SharingData", typeof(SharingData));
    class SharingData : MarshalByRefObject
        {
            public class HomeDataEventArgs : EventArgs
            {
                public string Param { get; private set; }
    
                public string SerialNo { get; private set; }
    
                public ModeConstant Mode { get; private set; }
    
                public string ContentId { get; private set; }
    
                public HomeDataEventArgs(string param, string serialNo, ModeConstant mode, string contentId)
                {
                    this.Param = param;
                    this.SerialNo = serialNo;
                    this.Mode = mode;
                    this.ContentId = contentId;
                }
            }
    
            public delegate void CallEventHandler(HomeDataEventArgs e);
            public event CallEventHandler OnNotify;
            public void DataNotify(string param, string serialNo, ModeConstant mode, string contentId)
            {
                OnNotify(new HomeDataEventArgs(param, serialNo, mode, contentId));
            }
    
            public override object InitializeLifetimeService()
            {
                return null;
            }
        }

    客户端:
    clientChannel = new IpcClientChannel();
    ChannelServices.RegisterChannel(clientChannel, true);
    sharingData = (SharingData)Activator.GetObject(typeof(SharingData), $"ipc://{ServerChannelId}/SharingData");  // 服务器中的ServerChannelId变量
    这里就完成了,客户端就可以拿到服务器的SharingData对象。
     
  • 相关阅读:
    配置文件
    ajax
    网线颜色排序
    cs程序添加初始化加载
    后台设置gridview不换行
    js 经典正则判断 一个字符串是否包含另一个字符串
    窗体关闭事件
    oracle根据视图删除表
    (字符串)哈希
    (字符串)哈希
  • 原文地址:https://www.cnblogs.com/ilison/p/12455431.html
Copyright © 2011-2022 走看看