-
-
Notifications
You must be signed in to change notification settings - Fork 970
Closed
Description
I want to get the Dispose state of the SftpClient instance outside.
This state allows me to decide when to reinitialize it.
Do you have any better advice?
Here's my sample code:
private SftpClient _ftpClient;
private SftpClient FtpClient
{
get
{
if (_ftpClient == null || IsDisposed)
{
_ftpClient = new SftpClient(Config.Host, Config.Port, Config.UserName, Config.Password);
}
return _ftpClient;
}
}
public virtual bool IsConnected
{
get
{
try
{
return FtpClient.IsConnected;
}
catch (Exception ex)
{
Log("FtpClient is disposed!", ex);
return false;
}
}
}
public virtual bool IsDisposed
{
get
{
try
{
return !FtpClient.IsConnected;
}
catch (Exception ex)
{
Log("FtpClient is disposed!", ex);
return true;
}
}
}Metadata
Metadata
Assignees
Labels
No labels