public MQTTPipe() { mqttClient = new MqttFactory().CreateMqttClient(); cancellationToken = new CancellationTokenSource(); // 设置断线重连 mqttClient.UseDisconnectedHandler(async e => { Tracker.LogNW(TAG, "disconnected"); using (new MethodUtils.Unlocker(this)) { OnDisconnectedCallback?.Invoke(); } await Task.Delay(TimeSpan.FromMilliseconds(RETRY_DURATION)); await ConnectAsync(); }); }
private void OnDisconnected() { using (new MethodUtils.Unlocker(this)) { OnDisconnectedCallback?.Invoke(); } }