I use Inetlab.SMPP Library to implement a RE (Routing Entity in SMPP 5.0 terms). I have some questions about Stop()
and Dispose()
methods of an SmppServer
instance:
- Is it necessary to call the
Stop()
method before disposingSmppServer
instance? - Does the
Stop()
method throw an exception ifSmppServer
instance is already stopped? - May the methods throw an exception?
So, is the following snippet correct?
class MyService : IHostedService, IDisposable
{
private readonly SmppServer _server = null;
public MyService()
{
_server = new SmppServer()
{
// configure SMPP server here
};
}
public Task StartAsync(CancellationToken cancellationToken)
{
_server.Start(cancellationToken);
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
_server.Stop();
return Task.CompletedTask;
}
public void Dispose()
{
_server?.Stop();
_server?.Dispose();
}
// implement logic here
}
Do I need to use try...catch
block within the Dispose()
method? Is it possible to exclude _server?.Stop()
line?