Ejemplo n.º 1
0
            private void SendMessageToFirstInstance(string[] args)
            {
                // Create an IPC client channel to request the existing SingleInstanceProxy object.
                _ipcChannel = _serviceProxy.NewClientChannel();

                // Register the channel and get it ready for use
                _serviceProxy.RegisterChannel(_ipcChannel);

                if (_disposed)
                    throw new ObjectDisposedException("The SingleInstanceTracker object has already been disposed.");

                if (_ipcChannel == null)
                    throw new InvalidOperationException(
                        "The object was constructed with the SingleInstanceTracker(string name) constructor overload, or with the SingleInstanceTracker(string name, SingleInstanceEnforcerRetriever enforcerRetriever) constructor overload, with enforcerRetriever set to null, thus you cannot send messages to the first instance.");

                // Retreive a reference to the proxy object which will be later used to send messages
                _proxy = _serviceProxy.Connect<SingleInstanceProxy>(_proxyUri);
                if (_proxy == null) return;

                try
                {
                    // Notify the first instance of the application that a new instance was created
                    _proxy.InvokeFirstInstance(args);
                }
                catch (Exception ex)
                {
                    throw new Exception(
                        "Failed to send message to the first instance of the application. The first instance might have terminated.",
                        ex);
                }
            }
Ejemplo n.º 2
0
            //private string GetUniqueName()
            //{
            //    var uniqueName = Assembly.GetEntryAssembly().GetName().Name;
            //    ThrowHelper.IfNullOrEmptyThenThrow(() => uniqueName);
            //    return uniqueName + Environment.UserName;
            //    //return name;
            //}
            private void CreateInstanceOfApplication(string channelName,
                SingleInstanceDelegate @delegate)
            {
                // Create an IPC server channel to listen for SingleInstanceProxy object requests
                _ipcChannel = _serviceProxy.CreateServerChannel(channelName);

                // Register the channel and get it ready for use
                _serviceProxy.RegisterChannel(_ipcChannel);

                // Register the service which gets the SingleInstanceProxy object,
                // so it can be accessible by IPC client channels
                _serviceProxy.RegisterType<SingleInstanceProxy>(ProxyObjectName);

                // Attempt to retrieve the enforcer from the delegated method
                _proxy = _factory.GetProxy(@delegate);

                // Publish the first proxy object so IPC clients
                // requesting a proxy would receive a reference to it
                _serviceProxy.Marshal(_proxy, ProxyObjectName);
            }