Skip to content

We has can public _isDisposed? #424

Closed
@VAllens

Description

@VAllens

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions