SerialPort and DataReceived Event
SerialPort and DataReceived Event
SerialPort and DataReceived Event
aspx
mySerialPort.DataReceived += MySerialPortDataReceviedHandler;
mySerialPort.Open();
The problem here is a lot more subtle, the customer opened the port setup MySerialPortDataReceviedHandler to handle
the DataReceived event and makes not calls to SerialPort.Close(). However the GC can actually close the port after Open
has been called since there are no more references to mySerialPort after this call. An object is eligible to be GC’d as soon
1 of 2 3/12/2010 12:38 PM
BCL Team Blog : SerialPort and DataReceived Event [Ryan Byington] http://blogs.msdn.com/bclteam/archive/2006/05/15/596656.aspx
as there are no more references to the object. You can read more about this at http://blogs.msdn.com/cbrumme/archive
/2003/04/19/51365.aspx. The fix is to make a call to SerialPort.Close() at the very end of the Main method. This keeps the
mySerialPort alive until the end of this method.
Comments
This is true (C# Code )if you have /DEBUG set to false in c# compiler or if you don't use VS.NET.
If you have try the same with VS.NET the object would not be collected.
Tuesday, October 10, 2006 4:40 PM by BCLTeam's WebLog
# Top 5 SerialPort Tips [Kim Hamilton]
The SerialPort class requires some “warming up” time for our users coming from VB6 or other
non-.NET
New Comments to this post are disabled
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
2 of 2 3/12/2010 12:38 PM