public async Task <TcpProxyThread> GetTcpProxy()
        {
            try
            {
                are.WaitOne();
                foreach (var item in tcpProxyThreads)
                {
                    if (!item.IsUsed)
                    {
                        item.IsUsed = true;
                        return(item);
                    }
                }
                if (tcpProxyThreads.Count >= maxTcpProxy)
                {
                    return(null);
                }
                TcpBase tcpProxy = new TcpBase(host, port);

                var result = await tcpProxy.Start();

                if (result.IsSuccess)
                {
                    var tcpProxyThread = new TcpProxyThread
                    {
                        IsUsed   = true,
                        TcpProxy = tcpProxy
                    };
                    tcpProxy.ConnectStateChanged += TcpProxy_ConnectStateChanged;
                    tcpProxyThreads.Add(tcpProxyThread);
                    return(tcpProxyThread);

                    //if (await Login(tcpProxy))
                    //{
                    //    var tcpProxyThread = new TcpProxyThread
                    //    {
                    //        IsUsed = true,
                    //        TcpBase = tcpProxy
                    //    };
                    //    tcpProxy.ConnectStateChanged += TcpProxy_ConnectStateChanged;
                    //    tcpProxyThreads.Add(tcpProxyThread);
                    //    return tcpProxyThread;
                    //}
                    //return tcpProxyThreads.Count > 0 ? tcpProxyThreads[0] : null;
                }
            }
            catch
            {
            }
            finally
            {
                are.Set();
            }
            return(null);
        }
 public void BackThread(TcpProxyThread tcpProxyThread)
 {
     are.WaitOne();
     tcpProxyThread.IsUsed = false;
     are.Set();
 }