Exit Application and application stops and does not dispose

  • Thread starter Thread starter nguyenxh
  • Start date Start date
N

nguyenxh

Guest
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...
 
Back
Top