public void close() { if (serial == null) { return; } connected = false; lock (nextlineLock) { try { serial.Close(); serial.Dispose(); } catch (Exception) { } serial = null; } job.KillJob(); history.Clear(); injectCommands.Clear(); resendNode = null; if (eventConnectionChange != null) { try { Main.main.Invoke(eventConnectionChange, "Disconnected"); } catch { } // Closing the app can cause an exception, if event comes after Main handle is destroyed } firePrinterAction("Idle"); Main.main.Invoke(Main.main.UpdateJobButtons); }
public void close() { if (serial == null) { return; } if (job.mode == 1) { job.KillJob(); } Application.DoEvents(); Thread.Sleep(100); Application.DoEvents(); connected = false; if (readThread != null) { readThread.Abort(); } readThread = null; // lock (nextlineLock) // { try { serial.Close(); serial.Dispose(); } catch (Exception) { } serial = null; // } job.KillJob(); history.Clear(); injectCommands.Clear(); resendNode = null; comErrorsReceived = 0; if (eventConnectionChange != null) { try { Main.main.Invoke(eventConnectionChange, "Disconnected"); } catch { } // Closing the app can cause an exception, if event comes after Main handle is destroyed } firePrinterAction("Idle"); Main.main.Invoke(Main.main.UpdateJobButtons); }