File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
55and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
66
7+ ## [ Unreleased]
8+ ### Fixed
9+ - IDisposable implementation.
10+
711## [ 2.2.0] - 2022-11-12
812### Changed
913- .NET 6.0 target to .NET Standard 2.0.
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ namespace PL.Modbus
1313 /// </summary>
1414 public class Client : IDisposable
1515 {
16+ private bool _disposed = false ;
1617 private readonly Protocol _protocol ;
1718 private readonly byte _stationAddress ;
1819
@@ -76,10 +77,21 @@ public int ReadTimeout
7677
7778 public void Dispose ( )
7879 {
79- _stream . Close ( ) ;
80+ Dispose ( true ) ;
8081 GC . SuppressFinalize ( this ) ;
8182 }
8283
84+ protected virtual void Dispose ( bool disposing )
85+ {
86+ if ( _disposed )
87+ return ;
88+
89+ if ( disposing )
90+ _stream . Dispose ( ) ;
91+
92+ _disposed = true ;
93+ }
94+
8395 /// <summary>
8496 /// Executes Modbus command.
8597 /// </summary>
Original file line number Diff line number Diff line change 1111 <RepositoryUrl >https://github.com/plasmapper/modbus-dotnet</RepositoryUrl >
1212 <RepositoryType >git</RepositoryType >
1313 <PackageTags >modbus;client</PackageTags >
14- <PackageReleaseNotes >Changed
15- - .NET 6.0 target to .NET Standard 2.0. </PackageReleaseNotes >
14+ <PackageReleaseNotes >Fixed
15+ - IDisposable implementation </PackageReleaseNotes >
1616 <PackageLicenseExpression >MIT</PackageLicenseExpression >
17- <VersionPrefix >2.2.0 </VersionPrefix >
17+ <VersionPrefix >2.2.1 </VersionPrefix >
1818 </PropertyGroup >
1919
2020 <PropertyGroup Condition =" '$(Configuration)|$(Platform)'=='Debug|AnyCPU'" >
Original file line number Diff line number Diff line change 33
44namespace PL . Modbus
55{
6- internal abstract class Stream
6+ internal abstract class Stream : IDisposable
77 {
8+ private bool _disposed = false ;
9+
810 public int ConnectTimeout { get ; set ; } = 1000 ;
911
1012 public int ReadTimeout { get ; set ; } = 300 ;
1113
1214 public int DelayBeforeWrite { get ; set ; } = 0 ;
1315
16+ public void Dispose ( )
17+ {
18+ Dispose ( true ) ;
19+ GC . SuppressFinalize ( this ) ;
20+ }
21+
22+ protected virtual void Dispose ( bool disposing )
23+ {
24+ if ( _disposed )
25+ return ;
26+
27+ if ( disposing )
28+ Close ( ) ;
29+
30+ _disposed = true ;
31+ }
32+
1433 public abstract byte [ ] Read ( int byteCount ) ;
1534
1635 public byte [ ] ReadTo ( byte termByte )
You can’t perform that action at this time.
0 commit comments