troubleshooting Question

Convert C# in VB 2005

Avatar of peter1950
peter1950 asked on
Visual Basic.NET
1 Comment1 Solution218 ViewsLast Modified:
Developing apps for WM6, frequently I have problems with serial port that hangs when I close it. I've found on a forum this code but I don't be able to convert in VB 2005.
Can somebody help me ?
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(); //close port in new thread to avoid hang
private void CloseSerialOnExit()
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

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros