• After more than 30 years running websites and forums I am retiring.

    I have made many friends through the years. I will cherish my time getting to know you. I wish you all the best. This was not an easy decision to make. The cost to keep the communities running has gotten to the point where it's just too expensive. Security certificates, hosting cost, software renewals and everything else has increased threefold. While costs are up ad revenue is down. It's no longer viable to keep things running.

    All sites will be turned off on Thursday 30 November 2023. If you are interested in acquiring any of the websites I own you can Email Schwarz Network.

Exit Application and application stops and does not dispose

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...
 
Top Bottom