mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-10-17 05:21:15 +08:00
Add Closed event to ShellStream. (#1332)
* Add `Closed` event to `ShellStream`. Lib consumer could hook to this event to detect if channel is closed by server **in time**. * handle `Closed` event on different thread. No need to block original thread.
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Renci.SshNet.Abstractions;
|
||||
using Renci.SshNet.Channels;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
@@ -44,6 +45,11 @@ namespace Renci.SshNet
|
||||
/// </summary>
|
||||
public event EventHandler<ExceptionEventArgs>? ErrorOccurred;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the channel was closed.
|
||||
/// </summary>
|
||||
public event EventHandler<EventArgs>? Closed;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether data is available on the <see cref="ShellStream"/> to be read.
|
||||
/// </summary>
|
||||
@@ -894,6 +900,12 @@ namespace Renci.SshNet
|
||||
private void Channel_Closed(object? sender, ChannelEventArgs e)
|
||||
{
|
||||
Dispose();
|
||||
|
||||
if (Closed != null)
|
||||
{
|
||||
// Handle event on different thread
|
||||
ThreadAbstraction.ExecuteThread(() => Closed?.Invoke(this, EventArgs.Empty));
|
||||
}
|
||||
}
|
||||
|
||||
private void Channel_DataReceived(object? sender, ChannelDataEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user