private void ProcessEvents() { var ct = _cts.Token; while (!ct.IsCancellationRequested) { var data = _tdJsonClient.Receive(0.1); if (!string.IsNullOrEmpty(data)) { try { var structure = JsonConvert.DeserializeObject <TdApi.Object>(data, _converter); Received?.Invoke(this, structure); if (structure is TdApi.Update.UpdateAuthorizationState update) { AuthorizationStateChanged?.Invoke(this, update.AuthorizationState); } } catch (Exception e) { ExceptionThrown?.Invoke(this, e); } } } }
private void ProcessEvents() { _cts = new CancellationTokenSource(); var state = new ReceiverInternalState(); var ct = _cts.Token; while (!ct.IsCancellationRequested) { var data = _tdJsonClient.Receive(1); if (!string.IsNullOrEmpty(data)) { var structure = JsonConvert.DeserializeObject <TdApi.Object>(data, new Converter()); UpdateState(ref state, structure); Received?.Invoke(this, structure); } PerformQueuedActions(ref state); } }