public ushort Publish(String Topic, String Message) { try { if (client.IsConnected == false || ((Queue)client.GetType().GetField("inflightQueue", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(client)).Count > 1) { this.connectInfinite(); Debug.Print("MQTT Publish store in sd: " + Message); MeasureDB.addMeasure(Message); return(0); } //PublishOld(Topic, Message); Debug.Print("MQTT Publish" + Message); try { ushort retval = client.Publish(Topic, Encoding.UTF8.GetBytes(Message), MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE, false); pendingSend.Add(retval, Message); return(retval); } catch (Exception) { Debug.Print("MQTT Publish pending FAILED"); MeasureDB.addMeasure(Message); //try { client.Disconnect();}catch (Exception) { }; return(0); } } catch (Exception) { //Debug.Print(e.StackTrace); Debug.Print("MQTT Publish FAILED"); return(0); } }