Guest nguyenxh Posted June 20, 2023 Posted June 20, 2023 Hello everyone, I got a problem in C#: in my application there are 2 serial ports communication and when I click on a button to exit whole application, I expect that application would exit but my case is the application stops without disposing: this is my code for event of button: Code Snippet private void Button_Exit_Application_Click(object sender, EventArgs e) { try { timer_Communication.Stop(); System.Threading.Thread.Sleep(10); if (comport.IsOpen) { comport.DiscardInBuffer(); comport.DiscardOutBuffer(); comport.Close(); comport.Dispose(); } if (readerPort.IsOpen) { readerPort.DiscardInBuffer(); readerPort.DiscardOutBuffer(); readerPort.Close(); readerPort.Dispose(); } runApplication.Close(); Application.Exit(); } catch (Exception ex) { MessageBox.Show("Bug 019\n" + ex.Message); } } I event try to stop port communication before closing the application but the problem still occurs. Could anyone know any solution, please help me? Thank you very much, Regards, Joesy Continue reading... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.