N
Nie longhai
Hi, all
I'm newbie in .net. I use SerialPort to control Hardware.
below is my test code:
===========================
namespace WindowsApplication6
{
public partial class Form1 : Form
{
MyPort m_port = new MyPort();
public Form1()
{
}
protected override void OnClosing(CancelEventArgs e)
{
MessageBox.Show("OnClosing: Port status=" + m_port.IsOpen);
base.OnClosing(e);
}
}
public class MyPort : SerialPort
{
public MyPort()
{
PortName = "COM1";
Open();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
MessageBox.Show("Dispose: Port status=" + IsOpen);
}
~MyPort()
{
MessageBox.Show("~MyCOM: Port status=" + IsOpen);
}
}
}
=======================
Debug Run. Close Form...
in Form's Closing(). the Port is Opened,
BUT in MyPort's Dispose() and ~MyPort(). the port is been CLOSED !!!!!!!,
Where and When the port been closed? It seems the GC close the port ?
I need send 'LogOut' Command before Port closed.
so How can I do ?
Can anyone give me somg advice ?
thanks
--
I'm newbie in .net. I use SerialPort to control Hardware.
below is my test code:
===========================
namespace WindowsApplication6
{
public partial class Form1 : Form
{
MyPort m_port = new MyPort();
public Form1()
{
}
protected override void OnClosing(CancelEventArgs e)
{
MessageBox.Show("OnClosing: Port status=" + m_port.IsOpen);
base.OnClosing(e);
}
}
public class MyPort : SerialPort
{
public MyPort()
{
PortName = "COM1";
Open();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
MessageBox.Show("Dispose: Port status=" + IsOpen);
}
~MyPort()
{
MessageBox.Show("~MyCOM: Port status=" + IsOpen);
}
}
}
=======================
Debug Run. Close Form...
in Form's Closing(). the Port is Opened,
BUT in MyPort's Dispose() and ~MyPort(). the port is been CLOSED !!!!!!!,
Where and When the port been closed? It seems the GC close the port ?
I need send 'LogOut' Command before Port closed.
so How can I do ?
Can anyone give me somg advice ?
thanks
--