/// <summary> /// 异步连接 /// </summary> private async Task ConnectAsync() { while (true) { try { // 连接 await mqttClient.ConnectAsync(options, cancellationToken.Token); using (new MethodUtils.Unlocker(this)) { OnConnectedCallback?.Invoke(); } return; } catch (Exception e) { Tracker.LogNW(TAG, "connect fail"); using (new MethodUtils.Unlocker(this)) { OnExceptionCallback?.Invoke(e); } await Task.Delay(TimeSpan.FromMilliseconds(RETRY_DURATION)); } } }
private void OnConnected() { using (new MethodUtils.Unlocker(this)) { OnConnectedCallback?.Invoke(); } }