diff --git a/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs b/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs index ee21ec7ef..8c344404b 100644 --- a/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs @@ -21,12 +21,17 @@ public static void Sleep(int millisecondsTimeout) public static void ExecuteThreadLongRunning(Action action) { + if (action == null) + throw new ArgumentNullException("action"); + #if FEATURE_THREAD_TAP var taskCreationOptions = System.Threading.Tasks.TaskCreationOptions.LongRunning; System.Threading.Tasks.Task.Factory.StartNew(action, taskCreationOptions); #else - var thread = new System.Threading.Thread(() => action()); - thread.Start(); + new System.Threading.Thread(() => action()) + { + IsBackground = true + }.Start(); #endif } diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index 0748b8dac..d2bf4bdf1 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -618,7 +618,8 @@ public void Connect() _messageListenerCompleted.Reset(); // Start incoming request listener - ThreadAbstraction.ExecuteThread(() => MessageListener()); + // ToDo: Make message pump async, to not consume a thread for every session + ThreadAbstraction.ExecuteThreadLongRunning(() => MessageListener()); // Wait for key exchange to be completed WaitOnHandle(_keyExchangeCompletedWaitHandle);