การ stop port serial และหยุด Thread ไม่ให้โปรแกรมค้าง ไปลอกเขามาอีกทีแต่จำเวปไม่ได้แล้ว
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (serialPort1.IsOpen)
{
e.Cancel = true; //cancel the fom closing
Thread CloseDown = new Thread(new ThreadStart(CloseSerialOnExit)); //close port in new thread to avoid hang
CloseDown.Start();
}
}
private void CloseSerialOnExit()
{
try
{
serialPort1.Close(); //close the serial port
}
catch (Exception ex)
{
MessageBox.Show(ex.Message); //catch any serial port closing error messages
}
this.Invoke(new EventHandler(NowClose)); //now close back in the main thread
}
private void NowClose(object sender, EventArgs e)
{
this.Close(); //now close the form
}
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)
2 ความคิดเห็น:
My family every time say that I am wasting my time here at web, except I know I am getting experience every day by reading thes fastidious articles or reviews.
my web page - simply click the up coming website page
I really like your blog.. very nice colors &
theme. Did you design this website yourself or did you hire someone to do it for you?
Plz respond as I'm looking to create my own blog and would like to know where u got this from. cheers
Review my blog post - Miami diet centers
My page > Miami diet centers
แสดงความคิดเห็น