示例#1
0
        public void AddListener()
        {
            PipeListener serverPipe = new PipeListener(Name);

            serverPipes.Add(serverPipe);

            serverPipe.DataReceived += (sndr, data) =>
            {
                //mDispatcher.BeginInvoke(new Action(() => {
                RemoteCall call = PipeListener.ByteArrayToObject(data);

                if (call.func == "InitSession")
                {
                    int SessionId = (int)call.args;

                    IPCSession session = new IPCSession();
                    //session.version = App.mVersion;
                    session.duplicate = mDispatcher.Invoke(new Func <bool>(() => {
                        return(CountSessions(SessionId) > 0);
                    }));
                    call.args = session;

                    serverPipe.SessionID = SessionId;
                }
                else
                {
                    call = Process(call);
                }

                serverPipe.Send(PipeListener.ObjectToByteArray(call));
                //}));
            };

            serverPipe.Connected += (sndr, args) =>
            {
                mDispatcher.BeginInvoke(new Action(() => {
                    // if we used a listener allocate a replacement one
                    AddListener();
                }));
            };

            serverPipe.PipeClosed += (sndr, args) =>
            {
                mDispatcher.BeginInvoke(new Action(() => {
                    serverPipes.Remove(serverPipe);
                }));
            };
        }
示例#2
0
        public int Connect(int TimeOut = 10000, bool mNoDouble = false)
        {
            // Note: when we close a IPC host without terminating its process we are left with some still active listeners, so we test communication and reconnect if needed
            for (long endTime = (long)MiscFunc.GetTickCount64() + (long)TimeOut; TimeOut > 0; TimeOut = (int)(endTime - (long)MiscFunc.GetTickCount64()))
            {
                if (!DoConnect(TimeOut))
                {
                    continue;
                }

                IPCSession session = RemoteExec <IPCSession>("InitSession", Process.GetCurrentProcess().SessionId, null);
                if (session != null)
                {
                    return((mNoDouble || session.duplicate == false) ? 1 : -1);
                }
            }
            return(0);
        }