private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (plc.isConnected) { plc.Disconnect(); } if (plc.isThreadRun) { plc.stop(); } }