Beispiel #1
0
        /// <summary>
        /// 取得一個未使用的client handler
        /// </summary>
        /// <returns></returns>
        public IClientRequestHandler GetInstance()
        {
            IClientRequestHandler result = null;

            lock (lockObj)
            {
                //get one client object that is not using, if none then create new
                result = this.dic.Where(n => { return(n.Value.IsUsed == false); }).FirstOrDefault().Value;
                //沒有就建一個新的ClientHandler
                if (result == null)
                {
                    this.ClientNo++;
                    result = new ClientRequestHandler(this.ClientNo);
                    this.dic.Add(this.ClientNo, (ClientRequestHandler)result);
                }
                ((ClientRequestHandler)result).IsUsed = true;
            }

            return(result);
        }
        /// <summary>
        /// 取得一個未使用的client handler
        /// </summary>
        /// <returns></returns>
        public IClientRequestHandler GetInstance()
        {
            IClientRequestHandler result = null;
            lock (lockObj)
            {
                //get one client object that is not using, if none then create new
                result = this.dic.Where(n => { return n.Value.IsUsed == false; }).FirstOrDefault().Value;
                //沒有就建一個新的ClientHandler
                if (result == null)
                {
                    this.ClientNo++;
                    result = new ClientRequestHandler(this.ClientNo);
                    this.dic.Add(this.ClientNo, (ClientRequestHandler)result);
                }
                ((ClientRequestHandler)result).IsUsed = true;
            }

            return result;
        }