public static bool TryGetClient(out CustomClient client)
        {
            bool isSuccess = false;

            try
            {
                lock (_lockObject)
                {
                    client = GetClient();
                    if (client != null) //doubleCheck
                    {
                        client.IsBusy = true;
                        isSuccess     = true;
                    }
                    else
                    {
                        isSuccess = false;
                    }
                }
                return(isSuccess);
            }
            catch (Exception)
            {
                isSuccess = false;
            }
            client = null;
            return(isSuccess);
        }
        private static CustomClient GetClient()
        {
            CustomClient client = null;

            if (_clients.Count() >= 0)
            {
                client = _clients.Where(x => !x.IsBusy).FirstOrDefault();
                if (client == null && _clients.Count < MaxConnections)
                {
                    client = new CustomClient(Guid.NewGuid());
                    _clients.Add(client);
                }
            }
            return(client);
        }
Exemplo n.º 3
0
 public MailProxy(string host, EncryptionType encryption, ref CustomClient client)
 {
     _host          = host;
     _encryptioType = encryption;
     _imapClient    = client;
 }