Jump to content
Xtreme .Net Talk

Exit Application and application stops and does not dispose


Recommended Posts

Guest nguyenxh
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...