protected override void AfterMyWorkStateChanged(object sender, EventArgs e) { if (myWorkState) { AiProtocol aiProtocol = new AiProtocol() { CaseNo = GateWaySetting.CaseNo, APISetting = APISetting }; AbsProtocols.Add(aiProtocol); StateProtocol stateProtocol = new StateProtocol() { CaseNo = GateWaySetting.CaseNo, APISetting = APISetting }; AbsProtocols.Add(stateProtocol); ReadThread = new Thread(Analysis); ReadThread.Start(); } else { if (ReadThread != null) { ReadThread.Abort(); } } }
private void Read() { try { StreamReader sReader = new StreamReader(Client.GetStream()); string msg = ""; while (true) { msg = sReader.ReadLine(); Console.WriteLine("{0}", msg); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { Client?.Close(); ReadThread.Abort(); } }
// null-safe & exception-safe: 2019-1-8 private bool EndListen() { // catch null here. if (ReadThread == null) { Debugger.Log("ReadThread is null.", Debugger.LogLevel.WARN); return(false); } // catch other exceptions here. try { ReadThread.Abort(); ReadThread = null; Debugger.Log("Successfully finished listening.", Debugger.LogLevel.INFO); Listening = false; return(true); } catch (Exception e) { Debugger.Log("Exception while aborting thread: \n" + e.ToString(), Debugger.LogLevel.ERROR); return(false); } }
public void Cancel() { ReaderRunning = false; ReadThread.Abort(); if (OscPacketIO.IsOpen()) { OscPacketIO.Close(); } }
public void Close() { try { Console.WriteLine($"Goodbye {Username}!"); TcpClient.Client.Close(); TcpClient.Close(); Program.Server.LeaveRoom(Username, Roomname); Program.Server.RemoveClient(Username); ReadThread.Abort(); } catch (Exception e) {} }
/** * Clear socket and threads */ private void Clear() { if (ReadThread.IsAlive) { ReadThread.Abort(); } if (WriteThread.IsAlive) { WriteThread.Abort(); } Socket.Close(); }
protected override void AfterMyWorkStateChanged(object sender, EventArgs e) { if (myWorkState) { ReadThread = new Thread(SqlRecord); ReadThread.Start(); } else { if (ReadThread != null) { ReadThread.Abort(); } } }
private void StopThreads() { lock (this) { if (ReadThread != null) { ReadThread.Abort(); ReadThread = null; } if (ReadTriggerThread != null) { ReadTriggerThread.Abort(); ReadTriggerThread = null; } } }
protected override void AfterMyWorkStateChanged(object sender, EventArgs e) { if (myWorkState) { APIMethod.APISetting = APISetting; ReadThread = new Thread(Analysis); ReadThread.Start(); } else { if (ReadThread != null) { ReadThread.Abort(); } } }
/// <summary> /// Verwendete Ressourcen bereinigen. /// </summary> /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } if (ReadThread != null && ReadThread.IsAlive) { ThreadActive = false; ReadThread.Join(50); ReadThread.Abort(); } if (ShmemChannel != null) { ShmemChannel.Unregister(); } base.Dispose(disposing); }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { ReadThread.Abort(); SaveOptions(); LogLine("Program terminated"); }
protected override void AfterMyWorkStateChanged(object sender, EventArgs e) { if (myWorkState) { foreach (var item in ElectricConfigs) { ElectricEnumType = (ElectricEnumType)item.ElectricEnumType; switch (ElectricEnumType) { case ElectricEnumType.PA310: { PA310Protocol protocol = new PA310Protocol() { GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType }; AbsProtocols.Add(protocol); } break; case ElectricEnumType.HC660: { HC6600Protocol protocol = new HC6600Protocol() { GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType }; AbsProtocols.Add(protocol); } break; case ElectricEnumType.CPM6: { CPM6Protocol protocol = new CPM6Protocol() { GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType }; AbsProtocols.Add(protocol); } break; case ElectricEnumType.PA60: { PA60Protocol protocol = new PA60Protocol() { GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType }; AbsProtocols.Add(protocol); } break; case ElectricEnumType.ABBM2M: { ABBM2MProtocol protocol = new ABBM2MProtocol() { GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType }; AbsProtocols.Add(protocol); } break; case ElectricEnumType.PM200: { PM200Protocol protocol = new PM200Protocol() { GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType }; AbsProtocols.Add(protocol); } break; case ElectricEnumType.TWCPM4: { TWCPM4Protocol protocol = new TWCPM4Protocol() { GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType }; AbsProtocols.Add(protocol); } break; } } ReadThread = new Thread(Analysis); ReadThread.Start(); } else { if (ReadThread != null) { ReadThread.Abort(); } } }