public bool CheckConnection(bool reconnect = false) { bool CheckFunc() => (TeamSpeakClient?.Client?.Client?.Connected ?? false) && (TeamSpeakClient?.Client?.IsConnected ?? false); if (CheckFunc()) { return(true); } if (!reconnect) { return(CheckFunc()); } try { lock (_ts3ClientSyncRoot) { if (CheckFunc()) { return(true); } if ((_lastReconnectTry + _ts3ServerInfo.QueryReconnectTimeout) > DateTime.Now) { return(false); } _lastReconnectTry = DateTime.Now; TeamSpeakClient?.Dispose(); TeamSpeakClient = new TeamSpeakClient(_ts3ServerInfo.QueryHostname, _ts3ServerInfo.QueryPort); TeamSpeakClient.ConnectAndInitConnection(_ts3ServerInfo).Wait(); } } catch (Exception ex) when(ex is QueryException || ex is QueryProtocolException) { //TODO: LOG return(false); } return(CheckFunc()); }