private async void SendNewData() { if (Client.IsConnected) { if (Interlocked.Exchange(ref IsSending, 1) == 0) { try { Nvqt nvqt = new Nvqt(); for (int i = 0; i < DataPointCount; i++) { string strVal = (Value += 1).ToString(); nvqt.Name = PointName(i); nvqt.Value = strVal; //strVal = JsonConvert.SerializeObject(nvqt); MqttApplicationMessage message = new MqttApplicationMessage() { Topic = nvqt.Name, Payload = Encoding.UTF8.GetBytes(strVal), QualityOfServiceLevel = QualityOfService, Retain = false } ; #if HAVE_SYNC if (IsSync) Client.Publish(message); else #endif await Client.PublishAsync(message); } UpdateCounts(DataPointCount, 0); } catch (Exception ex) { Console.WriteLine(ex.Message); } Interlocked.Exchange(ref IsSending, 0); } } }