Пример #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            try
            {
                if (_parent == null)
                {
                    if (_clientRequests != null)
                    {
                        // stop the request queue
                        _clientRequests.StopListening();
                    }
                }
                else
                {
                    if (_instance == _parent.Instance)
                    {
                        // LAME: Two Pipe objects can share the same pipe instance - that is
                        // the first pipe instance. In this case we could not close pipe as
                        // it can be the last one...
                        _instance.DisconnectFromClient();
                        _instance = null;
                    }
                    else if (!AppDomain.CurrentDomain.IsFinalizingForUnload())
                    {
                        // return instance back to the pool
                        _parent.InstancePool.StoreInstance(_instance);
                        _instance = null;
                    }
                }
                if (_instance != null)
                {
                    // close the pipe instance
                    _instance.Close();
                    _instance = null;
                }
            }
            catch
            {
                // it seems reasonable to ignore this error
            }

            _disposed = true;
        }
Пример #2
0
        public void StoreInstance(PipeInstance instance)
        {
            // parameters validation
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            if (instance.IsConnected)
            {
                try
                {
                    // we can reuse this instance later, so disconnect a client
                    // from the pipe to allow another client to connect
                    instance.DisconnectFromClient();
                }
                catch
                {
                    // we lose this instance...
                    instance.Close();
                    return;
                }
            }

            lock (_instances)
            {
                if (_instances.Count < _pipe.PoolSize)
                {
                    // store pipe instance for future use
                    _instances.Add(instance);
                }
                else
                {
                    // we are reach a maximum pool size, so simply close this instance
                    instance.Close();
                }
            }
        }
Пример #3
0
		public void StoreInstance(PipeInstance instance)
		{
			// parameters validation
			if (instance == null)
				throw new ArgumentNullException("instance");

			if (instance.IsConnected)
			{
				try
				{
					// we can reuse this instance later, so disconnect a client
					// from the pipe to allow another client to connect
					instance.DisconnectFromClient();
				}
				catch
				{
					// we lose this instance...
					instance.Close();
					return;
				}
			}

			lock (_instances)
			{
				if (_instances.Count < _pipe.PoolSize)
				{
					// store pipe instance for future use
					_instances.Add(instance);
				}
				else
				{
					// we are reach a maximum pool size, so simply close this instance
					instance.Close();
				}
			}
		}