Ignore ObjectDisposedException in AcceptAsync while stopping or stopped.

This commit is contained in:
drieseng
2016-07-22 20:12:42 +02:00
parent aa6792fead
commit 0a8673bf0c
2 changed files with 15 additions and 3 deletions
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Threading;
+15 -2
View File
@@ -79,9 +79,22 @@ namespace Renci.SshNet
// only accept new connections while we are started
if (IsStarted)
{
if (!_listener.AcceptAsync(e))
try
{
AcceptCompleted(null, e);
if (!_listener.AcceptAsync(e))
{
AcceptCompleted(null, e);
}
}
catch (ObjectDisposedException)
{
if (_status == ForwardedPortStatus.Stopped || _status == ForwardedPortStatus.Stopped)
{
// ignore ObjectDisposedException while stopping or stopped
return;
}
throw;
}
}
}