コード例 #1
0
        public bool PassCommand(string filename, string encoding)
        {
            IpcChannel clientChanel = new IpcChannel("myClient");

            ChannelServices.RegisterChannel(clientChanel, false);
            IMyPadServer obj = (IMyPadServer)Activator.GetObject(
                typeof(IMyPadServer),
                "ipc://" + GetChannelName() + "/" + GetObjectName());

            try
            {
                obj.OpenPage(filename, encoding);
                return(true);
            }
            catch (RemotingException)
            {
                // Connection refused
                return(false);
            }
            finally
            {
                ChannelServices.UnregisterChannel(clientChanel);
            }
        }
コード例 #2
0
        public ActionResult Verify_Login(Users_Data user_data)
        {
            HttpChannel channel = new HttpChannel();

            ChannelServices.RegisterChannel(channel);
            client = (ITwitterSentimentService.ITwitterSentimentService)Activator.GetObject
                         (typeof(ITwitterSentimentService.ITwitterSentimentService), "http://localhost:8080/CheckUser");


            string check_user = client.CheckUser(user_data.first_name, user_data.last_name);

            if (check_user == "Registered")
            {
                ChannelServices.UnregisterChannel(channel);
                int check = 1;
                return(this.Home(user_data, check));
            }
            else
            {
                ViewBag.check = 0;
                ChannelServices.UnregisterChannel(channel);
                return(View("Login"));
            }
        }
コード例 #3
0
    protected void joudmod_Click(object sender, EventArgs e)
    {
        HttpChannel chn33 = new HttpChannel();

        ChannelServices.RegisterChannel(chn33, false);

        IJournalManger serve = (IJournalManger)Activator.GetObject(typeof(IJournalManger), "http://localhost:1234/journalservice.soap");

        Journalshared showjou = new Journalshared();
        int           p       = int.Parse(searchtxt.Text);

        showjou.JId    = p;
        showjou.Jtitle = txtJtitle.Text;
        showjou.Jcity  = txtJcity.Text;
        showjou.Jsub   = txtJsub.Text;
        showjou.Jclass = int.Parse(txtJclass.Text);

        serve.modifaypaper(showjou);
        jouresult.Visible = false;
        joumod.Visible    = false;
        lblResult.Text    = " Journal Modfiy Succeded ";
        lblResult.Visible = true;
        ChannelServices.UnregisterChannel(chn33);
    }
コード例 #4
0
        private void BroadcastTake(DIDATuple didaTake)
        {
            string mypath     = System.Reflection.Assembly.GetEntryAssembly().Location;
            string finalpath  = mypath.Substring(0, mypath.Length - 10);
            string newpath    = Path.GetFullPath(Path.Combine(finalpath, @"..\..\"));
            string pathToList = newpath + "ListaServers.txt";

            string[] lines = System.IO.File.ReadAllLines(pathToList);
            foreach (string line in lines)
            {
                //port : name
                string[] args = line.Split(':');

                int    server_port = Int32.Parse(args[0]);
                string server_name = args[1];

                if (didaTake.getName() != server_name)
                {
                    try
                    {
                        string           url         = "tcp://localhost:" + server_port + "/" + server_name;
                        TcpClientChannel channelnovo = new TcpClientChannel(server_name, null);
                        ChannelServices.RegisterChannel(channelnovo, false);
                        IServerInterface servernovo = (IServerInterface)Activator.GetObject(typeof(IServerInterface), url);
                        DIDATuple        didaToSend = didaTake;
                        didaToSend.setName(server_name);

                        servernovo.Take(didaToSend, null, 0);
                        ChannelServices.UnregisterChannel(channelnovo);
                    }
                    catch
                    {
                    }
                }
            }
        }
コード例 #5
0
        public void Stop()
        {
            log.Info("Stopping");

            // Do this on a different thread since we need to wait until all messages are through,
            // including the message which is waiting for this method to return so it can report back.
            ThreadPool.QueueUserWorkItem(_ =>
            {
                log.Info("Waiting for messages to complete");

                // Wait till all messages are finished
                _currentMessageCounter.WaitForAllCurrentMessages();

                log.Info("Attempting shut down channel");

                // Shut down nicely
                _channel.StopListening(null);
                ChannelServices.UnregisterChannel(_channel);

                // Signal to other threads that it's okay to exit the process or start a new channel, etc.
                log.Info("Set stop signal");
                Agent.StopSignal.Set();
            });
        }
コード例 #6
0
        // Disconnect as from the server and remove client as listener
        public void DisconnectServer()
        {
            if (IsConnected && (Player != null))
            {
                // Remove the player from the game room
                gameRoom.Leave(Player);
            }

            if (channel != null)
            {
                ChannelDataStore cds = (ChannelDataStore)channel.ChannelData;

                foreach (string s in cds.ChannelUris)
                {
                    channel.StopListening(s);
                }

                ChannelServices.UnregisterChannel(channel);
            }

            gameRoom = null;
            Player   = null;
            channel  = null;
        }
コード例 #7
0
        public void Start()
        {
            Task.Factory.StartNew(() =>
            {
                var properties                    = new Hashtable();
                properties["portName"]            = typeof(IIpcClient).Name;
                properties["exclusiveAddressUse"] = false;
                properties["authorizedGroup"]     = "Everyone";

                var channel = new IpcChannel(properties, null, serverSinkProvider);

                try
                {
                    ChannelServices.RegisterChannel(channel, true);
                }
                catch
                {
                }

                var remoteObject = new RemoteObject(new _Server(this));

                RemotingServices.Marshal(remoteObject, typeof(RemoteObject).Name + ".rem");

                this.killer.WaitOne();

                RemotingServices.Disconnect(remoteObject);

                try
                {
                    ChannelServices.UnregisterChannel(channel);
                }
                catch
                {
                }
            });
        }
コード例 #8
0
ファイル: Controller.cs プロジェクト: IIITanbI/battleship
        public Player(ClientStatus status, Controller parent)
        {
            this.parent = parent;
            this.status = status;

            var channel = ChannelServices.GetChannel("tcp");

            if (channel != null)
            {
                ChannelServices.UnregisterChannel(channel);
            }

            if (status == ClientStatus.Client)
            {
                RemotingConfiguration.Configure("client.config", false);
                Utils.DumpAllInfoAboutRegisteredRemotingTypes();
                this.server = Activator.GetObject(typeof(IMyService), "tcp://localhost:33000/MyServiceUri") as IMyService;
            }
            else
            {
                RemotingConfiguration.Configure("server.config", false);
                Utils.DumpAllInfoAboutRegisteredRemotingTypes();
            }
        }
コード例 #9
0
        public void GetObjRefForProxy()
        {
            TcpChannel chn = new TcpChannel(1239);

            ChannelServices.RegisterChannel(chn);
            try
            {
                // Register le factory as a SAO
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObjectFactory), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap", WellKnownObjectMode.Singleton);

                MarshalObjectFactory objFactory = (MarshalObjectFactory)Activator.GetObject(typeof(MarshalObjectFactory), "tcp://localhost:1239/MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap");

                // Get a new "CAO"
                MarshalObject objRem = objFactory.GetNewMarshalObject();

                ObjRef objRefRem = RemotingServices.GetObjRefForProxy((MarshalByRefObject)objRem);

                Assert("#A11", objRefRem != null);
            }
            finally
            {
                ChannelServices.UnregisterChannel(chn);
            }
        }
コード例 #10
0
        public void btnStart_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (btnStart.Text == "&Start")
                {
                    tcp = new TcpChannel(8080);
                    ChannelServices.RegisterChannel(tcp);

                    RemotingConfiguration.RegisterWellKnownServiceType(typeof(Coba), "Demo", WellKnownObjectMode.Singleton);

                    btnStart.Text = "&Stop";
                }
                else
                {
                    btnStart.Text = "&Start";
                    ChannelServices.UnregisterChannel(tcp);
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
コード例 #11
0
        public void MarshalThrowException()
        {
            MarshalObject objMarshal = NewMarshalObject();

            IDictionary props = new Hashtable();

            props ["name"] = objMarshal.Uri;
            props ["port"] = 1237;
            TcpChannel chn = new TcpChannel(props, null, null);

            ChannelServices.RegisterChannel(chn);

            try
            {
                RemotingServices.Marshal(objMarshal, objMarshal.Uri);
                MarshalObject objRem = (MarshalObject)RemotingServices.Connect(typeof(MarshalObject), "tcp://localhost:1237/" + objMarshal.Uri);
                // This line should throw a RemotingException
                // It is forbidden to export an object which is not
                // a real object
                try
                {
                    RemotingServices.Marshal(objRem, objMarshal.Uri);
                    Fail("#1");
                }
                catch (RemotingException e)
                {
                }
            }
            finally
            {
                ChannelServices.UnregisterChannel(chn);

                // TODO: uncomment when RemotingServices.Disconnect is implemented
                //RemotingServices.Disconnect(objMarshal);
            }
        }
コード例 #12
0
        public void Connect()
        {
            MarshalObject objMarshal = NewMarshalObject();

            IDictionary props = new Hashtable();

            props ["name"] = objMarshal.Uri;
            props ["port"] = 1236;
            TcpChannel chn = new TcpChannel(props, null, null);

            ChannelServices.RegisterChannel(chn);

            try
            {
                RemotingServices.Marshal(objMarshal, objMarshal.Uri);
                MarshalObject objRem = (MarshalObject)RemotingServices.Connect(typeof(MarshalObject), "tcp://localhost:1236/" + objMarshal.Uri);
                Assert("#A08", RemotingServices.IsTransparentProxy(objRem));
            }
            finally
            {
                ChannelServices.UnregisterChannel(chn);
                RemotingServices.Disconnect(objMarshal);
            }
        }
コード例 #13
0
ファイル: loja.cs プロジェクト: vetongacaferi/Guess-Game_chat
        private void JoinToChatRoom()
        {
            if (chan == null && username.Trim().Length != 0)
            {
                chan = new TcpChannel();
                ChannelServices.RegisterChannel(chan, false);



                remoteObj = (SampleObject)Activator.GetObject(typeof(RemoteBase.SampleObject), "tcp://localhost:8080/ProjektiPSH");

                if (!remoteObj.JoinToChatRoom(username))
                {
                    MessageBox.Show(username + " ekziston ne linje!");
                    ChannelServices.UnregisterChannel(chan);
                    chan = null;
                    this.Dispose();
                    return;
                }
                key = remoteObj.CurrentKeyNo();

                yourName = username;
            }
        }
コード例 #14
0
        /// <summary>
        /// 取门诊结算结果(事后查询用)
        /// </summary>
        /// <param name="mzlsh">门诊流水号</param>
        /// <param name="djh">单据号</param>
        /// <param name="theMZJSJG">结算信息</param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool GetMZJSJG(string mzlsh, string djh, out MZJSJG theMZJSJG, out string errMsg)
        {
            IiopClientChannel channel = new IiopClientChannel();

            try
            {
                ChannelServices.RegisterChannel(channel, false);
                NamingContext   nameService = (NamingContext)RemotingServices.Connect(typeof(NamingContext), strior);
                NameComponent[] name        = new NameComponent[] { new NameComponent("MZYL", "Service") };
                intMZ           mz          = (intMZ)nameService.resolve(name);
                short[]         res         = mz.GetMZJSJG(yljgbm, mzlsh, djh, czybm, czy, out theMZJSJG);
                ChannelServices.UnregisterChannel(channel);
                string resStr = TransSAToString(res);
                if (resStr.StartsWith(SUCCESS))
                {
                    errMsg = string.Empty;
                    return(true);
                }
                else
                {
                    errMsg = resStr.Substring(resStr.IndexOf(")") + 1);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                ChannelServices.UnregisterChannel(channel);
                if (isSaveExceptionLog)
                {
                    //DataLog.SaveLog(String.Format("GetMZJSJG:{0}\n", ex.Message));
                }
                errMsg    = EXCEPTION;
                theMZJSJG = new MZJSJG();
                return(false);
            }
        }
コード例 #15
0
        public void Stop()
        {
            lock (this)
            {
                if (!started)
                {
                    return;
                }

                if (!ConfigCache.LocalOnly)
                {
                    foreach (MarshalByRefObject obj in services)
                    {
                        RemotingServices.Disconnect(obj);
                    }

                    ChannelServices.UnregisterChannel(channel);
                    channel.StopListening(null);
                }
                //Context.UnregisterDynamicProperty(DefaultDynamicProperty.PropertyName, null, null);
                //ChannelServices.UnregisterChannel(channel);
                started = false;
            }
        }
コード例 #16
0
    protected void search_Click(object sender, EventArgs e)
    {
        papershare showpap = new papershare();

        int         p    = int.Parse(searchtxt.Text);
        HttpChannel chn5 = new HttpChannel();

        ChannelServices.RegisterChannel(chn5, false);

        Ipaperservice serve = (Ipaperservice)Activator.GetObject(typeof(Ipaperservice), "http://localhost:1234/papmanger.soap");

        showpap = serve.retrivepaper(p);



        txtPJtitle.Text          = showpap.JTitle;
        txtPabstract.Text        = showpap.PAbstract;
        txtPauthers.Text         = showpap.Pauther;
        txtin.Text               = Convert.ToString(showpap.PInumber);
        txtkeywords.Text         = showpap.PKeywords;
        txtPnunmerofauthers.Text = Convert.ToString(showpap.PNofauthers);
        txtpj2.Text              = Convert.ToString(showpap.PPagesF);
        txtpj1.Text              = Convert.ToString(showpap.PPagesN);
        txtPtitle.Text           = showpap.PTitle;
        txtvn.Text               = Convert.ToString(showpap.PVnumber);
        txtYearofpublishing.Text = Convert.ToString(showpap.PYear);



        paperresult.Visible = true;
        paperupdate.Enabled = true;
        paperupdate.Visible = true;
        errorresult.Visible = true;

        ChannelServices.UnregisterChannel(chn5);
    }
コード例 #17
0
        private void Connect()
        {
            ACA.LabelX.Client.RemClientControlObject theObj;

            Start();

            theObj = (ACA.LabelX.Client.RemClientControlObject)Activator.GetObject(typeof(ACA.LabelX.Client.RemClientControlObject), ServerUrl);
            if (theObj == null)
            {
                RemClientControlObjectProxyException ex;
                ex = new RemClientControlObjectProxyException("Could not connect", 0x01);
                //MessageBox.Show("Could not connect to the printer server.");
                ChannelServices.UnregisterChannel(channel);
                channel     = null;
                isConnected = false;
                remoteObj   = null;
                throw (ex);
            }
            else
            {
                remoteObj   = theObj;
                isConnected = true;
            }
        }
コード例 #18
0
        public void Start()
        {
            Task.Factory.StartNew(() =>
            {
                //var properties = new Hashtable { ["portName"] = typeof(IContract).Name };
                RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
                var channel = new TcpChannel(21000);

                try
                {
                    ChannelServices.RegisterChannel(channel, true);
                }
                catch
                {
                    //might be already registered, ignore it
                }

                RemotingConfiguration.RegisterWellKnownServiceType(typeof(InternalRemotingServer), "remoteObject", WellKnownObjectMode.Singleton);

                //var remoteObject = new RemoteObject(new InternalRemotingServer(this));

                //RemotingServices.Marshal(remoteObject, typeof(RemoteObject).Name + ".rem");

                killer.WaitOne();

                //RemotingServices.Disconnect(remoteObject);

                try
                {
                    ChannelServices.UnregisterChannel(channel);
                }
                catch
                {
                }
            });
        }
コード例 #19
0
        /// <summary>
        /// 停止此服务。
        /// </summary>
        protected void OnStop()
        {
            // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
            try
            {
                if (ChannelServices.RegisteredChannels.Length > 0)
                {
                    IChannel[] channels = ChannelServices.RegisteredChannels;

                    //					现在改成TCP、HTTP的都能停
                    for (int i = 0; i < channels.Length; i++)
                    {
                        string sChannelName = channels[i].ChannelName;
                        if (sChannelName == "tcp")
                        {
                            TcpServerChannel channel = (TcpServerChannel)channels[i];
                            channel.StopListening(null);
                            ChannelServices.UnregisterChannel(channel);
                        }
                        else
                        {
                            HttpServerChannel channel = (HttpServerChannel)channels[i];
                            channel.StopListening(null);
                            ChannelServices.UnregisterChannel(channel);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                System.Windows.Forms.MessageBox.Show("连接数据库出错" + exception.ToString(), "操作提示");
            }
            finally
            {
            }
        }
コード例 #20
0
        public void HandleConnectionProblem()
        {
            Runner runner = new Runner();

            runner.Url = "tcp://localhost:2134/NoRunningServer.rem";
            try
            {
                runner.Run("project");
                Fail("Expected exception");
            }
            catch (Exception ex)
            {
                AssertEquals(typeof(ServerConnectionException), ex.GetType());
            }
            finally
            {
                // NB. For some reason, .NET opens a client channel and doesn't close it when the server does not exist.
                if (ChannelServices.RegisteredChannels.Length > 0)
                {
                    Console.WriteLine("Channel: " + ChannelServices.RegisteredChannels[0].ChannelName);
                    ChannelServices.UnregisterChannel(ChannelServices.RegisteredChannels[0]);
                }
            }
        }
コード例 #21
0
        public ActionResult Verify_retrieveusers_case(RetrieveUsers_case_Data ret)
        {
            ViewBag.check = true;

            HttpChannel channel = new HttpChannel();

            ChannelServices.RegisterChannel(channel);
            client = (ITwitterSentimentService.ITwitterSentimentService)Activator.GetObject
                         (typeof(ITwitterSentimentService.ITwitterSentimentService), "http://localhost:8080/RetrieveUsers_case");

            ArrayList user_retrieve = client.RetrieveUsers_case(ret.case_id);

            if (user_retrieve != null)
            {
                ViewBag.users = user_retrieve;
            }

            else
            {
                ViewBag.users = null;
            }
            ChannelServices.UnregisterChannel(channel);
            return(View("RetrieveUsers_case"));
        }
コード例 #22
0
        public void SetObjectUriForMarshal()
        {
            TcpChannel chn = null;

            try
            {
                chn = new TcpChannel(1242);
                ChannelServices.RegisterChannel(chn);

                MarshalObject objRem = NewMarshalObject();
                RemotingServices.SetObjectUriForMarshal(objRem, objRem.Uri);
                RemotingServices.Marshal(objRem);

                objRem = (MarshalObject)Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1242/" + objRem.Uri);
                Assert.IsTrue(objRem != null, "#A14");
            }
            finally
            {
                if (chn != null)
                {
                    ChannelServices.UnregisterChannel(chn);
                }
            }
        }
コード例 #23
0
ファイル: ProcessWorker.cs プロジェクト: thyawan/storybrew
        public static void Run(string identifier)
        {
            //if (!Debugger.IsAttached) Debugger.Launch();

            Trace.WriteLine($"channel: {identifier}");
            try
            {
                var name    = $"sbrew-worker-{identifier}";
                var channel = new IpcServerChannel(name, name, new BinaryServerFormatterSinkProvider()
                {
                    TypeFilterLevel = TypeFilterLevel.Full
                });

                ChannelServices.RegisterChannel(channel, false);
                try
                {
                    RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteProcessWorker), "worker", WellKnownObjectMode.Singleton);
                    Trace.WriteLine($"ready\n");

                    while (!exit)
                    {
                        Program.RunScheduledTasks();
                        Thread.Sleep(100);
                    }
                }
                finally
                {
                    Trace.WriteLine($"unregistering channel");
                    ChannelServices.UnregisterChannel(channel);
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine($"ProcessWorker failed: {e}");
            }
        }
コード例 #24
0
ファイル: CargoHostEndPoint.cs プロジェクト: marzlia/CXPortal
        public void RebindToNameService()
        {
            try
            {
                if (/*exists (avoid first try exceptions)?*/ _nameService != null)
                {
                    _nameService.rebind(_ncXi, new XiManagerCallback());
                }
            }
            catch
            {
                _nameService = null;
#if false
                // HACK! ChannelServices.UnregisterChannel hangs.
                ChannelServices.UnregisterChannel(_iiopChannel);
#endif
                throw;
            }
            finally
            {
                _nameService = null;
                _iiopChannel = null;
            }
        }
コード例 #25
0
        /// <summary>
        /// Cleans up single-instance code, clearing shared resources, mutexes, etc.
        /// </summary>
        public static void Cleanup()
        {
            if (_singleInstanceMutex != null)
            {
                if (_isFirstInstance)
                {
                    _singleInstanceMutex.ReleaseMutex();
                }

                _singleInstanceMutex.Close();
                _singleInstanceMutex = null;
            }

            if (_channel != null)
            {
                ChannelServices.UnregisterChannel(_channel);
                _channel = null;
            }

            _callback        = null;
            _commandLineArgs = null;
            _channelName     = null;
            _isFirstInstance = false;
        }
コード例 #26
0
        public static void Main(string[] args)
        {
            Console.Clear();
            Console.WriteLine();
            Console.WriteLine("PCS");
            Console.WriteLine("listening on tcp://" + PCS.GetLocalIPAddress() + ":10000/pcs");

            TcpChannel channel = new TcpChannel(10000);

            ChannelServices.RegisterChannel(channel, false);

            PCS pcs = new PCS();

            RemotingServices.Marshal(pcs, "pcs", typeof(IPCS));

            // Dont close console
            Console.ReadLine();

            // Close TcpChannel
            channel.StopListening(null);
            RemotingServices.Disconnect(pcs);
            ChannelServices.UnregisterChannel(channel);
            channel = null;
        }
コード例 #27
0
ファイル: SCBController.cs プロジェクト: icprog/SCBEmulator
        private void UnregisterPCUService()
        {
            try
            {
                IChannel[] channels = ChannelServices.RegisteredChannels;


                foreach (IChannel eachChannel in channels)
                {
                    if (eachChannel.ChannelName == "PCUChannel")
                    {
                        TcpChannel tcpChannel = (TcpChannel)eachChannel;


                        tcpChannel.StopListening(null);

                        ChannelServices.UnregisterChannel(tcpChannel);
                    }
                }
            }
            catch (Exception)
            {
            }
        }
コード例 #28
0
        public void GetRealProxy()
        {
            var         port  = NetworkHelpers.FindFreePort();
            IDictionary props = new Hashtable();

            props ["port"]   = port;
            props ["bindTo"] = "127.0.0.1";
            TcpChannel chn = new TcpChannel(props, null, null);

            ChannelServices.RegisterChannel(chn);
            try {
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap", WellKnownObjectMode.Singleton);

                MyProxy       proxy  = new MyProxy(typeof(MarshalObject), (MarshalByRefObject)Activator.GetObject(typeof(MarshalObject), $"tcp://localhost:{port}/MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap"));
                MarshalObject objRem = (MarshalObject)proxy.GetTransparentProxy();

                RealProxy rp = RemotingServices.GetRealProxy(objRem);

                Assert.IsNotNull(rp, "#A12");
                Assert.AreEqual("MonoTests.System.Runtime.Remoting.RemotingServicesInternal.MyProxy", rp.GetType().ToString(), "#A13");
            } finally {
                ChannelServices.UnregisterChannel(chn);
            }
        }
コード例 #29
0
            /// <summary>
            /// Implements remote server.
            /// </summary>
            private static void RunServer(string serverPort, string semaphoreName, int clientProcessId)
            {
                if (!AttachToClientProcess(clientProcessId))
                {
                    return;
                }

                // Disables Windows Error Reporting for the process, so that the process fails fast.
                // Unfortunately, this doesn't work on Windows Server 2008 (OS v6.0), Vista (OS v6.0) and XP (OS v5.1)
                // Note that GetErrorMode is not available on XP at all.
                if (Environment.OSVersion.Version >= new Version(6, 1, 0, 0))
                {
                    SetErrorMode(GetErrorMode() | ErrorMode.SEM_FAILCRITICALERRORS | ErrorMode.SEM_NOOPENFILEERRORBOX | ErrorMode.SEM_NOGPFAULTERRORBOX);
                }

                IpcServerChannel serverChannel = null;
                IpcClientChannel clientChannel = null;

                try
                {
                    using (var semaphore = Semaphore.OpenExisting(semaphoreName))
                    {
                        // DEBUG: semaphore.WaitOne();

                        var serverProvider = new BinaryServerFormatterSinkProvider();
                        serverProvider.TypeFilterLevel = TypeFilterLevel.Full;

                        var clientProvider = new BinaryClientFormatterSinkProvider();

                        clientChannel = new IpcClientChannel(GenerateUniqueChannelLocalName(), clientProvider);
                        ChannelServices.RegisterChannel(clientChannel, ensureSecurity: false);

                        serverChannel = new IpcServerChannel(GenerateUniqueChannelLocalName(), serverPort, serverProvider);
                        ChannelServices.RegisterChannel(serverChannel, ensureSecurity: false);

                        RemotingConfiguration.RegisterWellKnownServiceType(
                            typeof(Service),
                            ServiceName,
                            WellKnownObjectMode.Singleton);

                        using (var resetEvent = new ManualResetEventSlim(false))
                        {
                            var uiThread = new Thread(() =>
                            {
                                s_control = new Control();
                                s_control.CreateControl();
                                resetEvent.Set();
                                Application.Run();
                            });
                            uiThread.SetApartmentState(ApartmentState.STA);
                            uiThread.IsBackground = true;
                            uiThread.Start();
                            resetEvent.Wait();
                        }

                        // the client can instantiate interactive host now:
                        semaphore.Release();
                    }

                    s_clientExited.Wait();
                }
                finally
                {
                    if (serverChannel != null)
                    {
                        ChannelServices.UnregisterChannel(serverChannel);
                    }

                    if (clientChannel != null)
                    {
                        ChannelServices.UnregisterChannel(clientChannel);
                    }
                }

                // force exit even if there are foreground threads running:
                Environment.Exit(0);
            }
コード例 #30
0
ファイル: IPCServer.cs プロジェクト: yycmmc/SoundSwitch
 public void Dispose()
 {
     _ipcServer.StopListening(null);
     ChannelServices.UnregisterChannel(_ipcServer);
 }