[BF] Fehler behoben, das sich die Anwendung nicht beendet

This commit is contained in:
BlubbFish 2017-08-10 09:41:47 +00:00
parent 241b0ca00a
commit 3b5b2287b2
5 changed files with 43 additions and 12 deletions

View File

@ -5,7 +5,7 @@ using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace Dashboard.Connector {
class Mqtt {
class Mqtt : IDisposable {
private static Mqtt instance;
private MqttClient client;
@ -37,5 +37,29 @@ namespace Dashboard.Connector {
public void Send(String topic, String data) {
this.client.Publish(topic, Encoding.UTF8.GetBytes(data));
}
#region IDisposable Support
private bool disposedValue = false;
protected virtual void Dispose(bool disposing) {
if(!disposedValue) {
if(disposing) {
this.client.MqttMsgPublishReceived -= this.Client_MqttMsgPublishReceived;
this.client.Unsubscribe(new String[] { "#" });
this.client.Disconnect();
}
this.client = null;
disposedValue = true;
}
}
~Mqtt() {
Dispose(false);
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}

View File

@ -28,7 +28,7 @@ namespace Dashboard {
Mqtt.Instance.MessageIncomming += this.Instance_MessageIncomming;
}
private void GenerateSensors() {
private void GenerateSensors() {
InIReader ini = InIReader.GetInstance("sensor.ini");
List<String> sensorini = ini.GetSections();
foreach(String sensor in sensorini) {
@ -68,11 +68,9 @@ namespace Dashboard {
private new void Dispose() {
this.updateThread.Abort();
while (this.updateThread.ThreadState != ThreadState.Aborted) { }
foreach (String item in this.sensors.Keys) {
this.sensors[item] = null;
}
this.sensors.Clear();
Mqtt.Instance.MessageIncomming -= this.Instance_MessageIncomming;
Mqtt.Instance.Dispose();
this.Dispose(true);
}
private void Instance_MessageIncomming(Object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e) {

View File

@ -1,7 +1,7 @@
[Thinkpad]
topic=zway/wohnzimmer/thinkpad/power
type=Power
polling=10
;[Thinkpad]
;topic=zway/wohnzimmer/thinkpad/power
;type=Power
;polling=10
;[Tv]
;topic=zway/wohnzimmer/tV/power
@ -11,4 +11,9 @@ polling=10
;[Kühlschrank]
;topic=zway/küche/kuehlschrank/power
;type=Power
;polling=10
;polling=10
[Ventilator]
topic=zway/power/test/wVentilator
type=Power
polling=10

View File

@ -1,2 +1,2 @@
[general]
mqtt-server=localhost
mqtt-server=129.26.160.65

View File

@ -8,4 +8,8 @@
;[KühlschrankGraph]
;sensor=Kühlschrank
;type=Graph
;type=Graph
[VentilatorGraph]
sensor=Ventilator
type=Graph