void Initialize(string uniqueName, string itemName)
            {
                var channel = new IpcServerChannel(uniqueName);                            // このアプリケーション独自の名前で IPC (プロセス間通信) サーバー チャンネルを作成

                ChannelServices.RegisterChannel(channel, true);                            // チャンネルを登録
                remoteObject = new IpcRemoteObject();                                      // リモートオブジェクトを生成
                RemotingServices.Marshal(remoteObject, itemName, typeof(IpcRemoteObject)); // リモートオブジェクトを公開
            }
Beispiel #2
0
        public IpcServer()
        {
            // Create the server channel.
            IpcServerChannel channel = new IpcServerChannel("ipcSample");

            // Register the server channel.
            ChannelServices.RegisterChannel(channel, true);

            // Create an instance of the remote object.
            RemoteObject = new IpcRemoteObject();

            RemoteObject.URL = "URL";
            RemotingServices.Marshal(RemoteObject, "test", typeof(IpcRemoteObject));
        }
            // 初期化 (戻り値が偽の場合は終了)
            public bool Initialize(ITicker ticker, string documentPath = "", Action <string> open = null)
            {
                var applicationProductName = ((AssemblyProductAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyProductAttribute))).Product;

                singleton = new Singleton(applicationProductName);
                if (singleton.IsExist)                                                    // 既に他のプロセスが起動していたら
                {
                    IpcRemoteObject.Send(applicationProductName, itemName, documentPath); // その起動済みのプロセスにドキュメントのパスを送信して
                    return(false);                                                        // 終了する
                }
                receiver = new Receiver(applicationProductName, itemName, ticker);
                if (open != null)
                {
                    receiver.Receive += item => open((string)item); // Receive イベントが起きたらアイテムを open するように設定
                    if (!string.IsNullOrWhiteSpace(documentPath))   // documentPath が空でなければ
                    {
                        open(documentPath);                         // documentPath を開く
                    }
                }
                return(true); // 終了しない
            }