Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Disposable #67

Closed
taai opened this issue May 15, 2022 · 2 comments
Closed

Implement Disposable #67

taai opened this issue May 15, 2022 · 2 comments

Comments

@taai
Copy link

taai commented May 15, 2022

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
}
@Apollo3zehn
Copy link
Owner

Good suggestion, please go ahead :-)

@Apollo3zehn
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants