Skip to content

We has can public _isDisposed? #424

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

Closed
VAllens opened this issue Apr 23, 2018 · 6 comments
Closed

We has can public _isDisposed? #424

VAllens opened this issue Apr 23, 2018 · 6 comments

Comments

@VAllens
Copy link

VAllens commented Apr 23, 2018

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;
		}
	}
}
@keithallenjackson
Copy link

See PL #458

@VAllens
Copy link
Author

VAllens commented Aug 18, 2018

This is great, thank you.

@drieseng
Copy link
Member

A SSH.NET client (SFTP, SSH, …) is only ever disposed when Dispose() is invoked by user code. I don't see why you'd need to have a (Is)Disposed property.

@keithallenjackson
Copy link

drieseng commented 2 hours ago
A SSH.NET client (SFTP, SSH, …) is only ever disposed when Dispose() is invoked by user code. I don't see why you'd need to have a (Is)Disposed property.

Actually, Dispose is also called when the channel closes abruptly. See my issue #453. This is one of the main issues PL #458 tries to address. This causes the ShellStream to Dispose without the user explicitly doing so.

I can continue to discuss ways forward to address this issue in the actual PL. I'm not hard-set on the current PL implementation and completely understand if it appears a bit 'hackish.' Let's make work and make it 'right' 😃

lipmas added a commit to bastionzero/SSH.NET that referenced this issue Oct 29, 2020
@IgorMilavec
Copy link
Collaborator

I have created a discussion #926 for all ShellStream related issues.

@WojciechNagorski
Copy link
Collaborator

SSH.NET version 2024.0.0 has changed a lot. I'm closing the ticket, but if the problem still persists, please feel free to reopen or open a new ticket.

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

5 participants