コード例 #1
0
ファイル: Program.cs プロジェクト: rambothanh/SteamShutdown
        private static bool EnsureSingleInstance()
        {
            string appProcessName = Path.GetFileNameWithoutExtension(Application.ExecutablePath);

            Process[] RunningProcesses = Process.GetProcessesByName(appProcessName);

            // IPC: https://gorillacoding.wordpress.com/2013/02/03/using-wcf-for-inter-process-communication/
            const string        address = "net.pipe://localhost/SteamShutdown/ShowBalloonTip";
            NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);

            if (RunningProcesses.Length == 1)
            {
                // Only running process. This process is the server of IPC
                ServiceHost serviceHost = new ServiceHost(typeof(IPCBubbleServer));
                serviceHost.AddServiceEndpoint(typeof(IBubbleContract), binding, address);
                serviceHost.Open();
                return(true);
            }
            else
            {
                // Already running. This process is the client of IPC
                EndpointAddress ep      = new EndpointAddress(address);
                IBubbleContract channel = ChannelFactory <IBubbleContract> .CreateChannel(binding, ep);

                channel.ShowAnInstanceIsRunning();
                return(false);
            }
        }
コード例 #2
0
ファイル: IPC.cs プロジェクト: zAlweNy26/SteamShutdown
        public static void ShowAnInstanceIsRunning()
        {
            NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
            EndpointAddress     ep      = new EndpointAddress(address);
            IBubbleContract     channel = ChannelFactory <IBubbleContract> .CreateChannel(binding, ep);

            channel.ShowAnInstanceIsRunning();
        }