I have created a library class for a control circuit which communicates through a serial port and is used in WinForms. When the class is initialized the serial port is opened
CircuitController controller = new CircuitController("Controller1", COM8, Baud9600, ...);
But what is the appropriate way to close the serial port when I exit the WinForm application? Should this be called on the controller specifically
(On close) --> controller.Shutdown();
Or will the serial port automatically close when the Form is closed?
Per ildjarn’s suggestion:
The best thing to do here is implement
IDisposable, and close your port there. You can find some excellent example code for doing this on MSDN:http://msdn.microsoft.com/en-us/library/system.idisposable.aspx