FluentModbus icon indicating copy to clipboard operation
FluentModbus copied to clipboard

Implement Disposable

Open taai opened this issue 3 years ago • 1 comments

I suggest to implement IDisposable. It is simpler to disconnect, if IDisposable is implemented.

When code gets complicated, you have two options:

  • call Disconnect() in multiple places
  • wrap all your code with try-finally and call Disconnect() only once in finally block

I offer implement this. Do you agree and should I make a PR? 😉

Currently:

var client = new ModbusTcpClient();
// code here ...
// disconnect
client.Disconnect();

Suggestion:

using (var client = new ModbusTcpClient())
{
    // code here ...
    // will disconnect automatically
}

taai avatar May 15 '22 15:05 taai

Good suggestion, please go ahead :-)

Apollo3zehn avatar May 15 '22 18:05 Apollo3zehn

I has implemented it in v5, so I am closing this issue for now.

Apollo3zehn avatar Sep 08 '22 09:09 Apollo3zehn