public T Get <T>(Message msg, ServiceConfig serviceSettings) { var res = default(T); var client = pool.GetObject(); try { res = client.Reqvest <T>(msg, serviceSettings); } catch (Exception e) { Console.WriteLine(e.Message); string theadName = Thread.CurrentThread.Name; try { client.StopClient(); } catch (Exception ex) { log.LogError($"В потока { theadName } при выключении сокета произошла ошибка socet", ex); } client = new AscClient(config, log); } pool.PutObject(client); if (res == null) { throw new Exception("Не получилось получить данные"); } return(res); }
private void CreatePool(ConnectionSettings connectionSettings, int connectionPoolSize, ILogger log) { var ascPool = new AscClient[connectionPoolSize]; for (int i = 0; i < connectionPoolSize; i++) { ascPool[i] = new AscClient(connectionSettings, log); ascPool[i].StartClient(); } pool = new MyObjectPool <AscClient>(ascPool); }