Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 6 additions & 19 deletions src/Renci.SshNet/Abstractions/ThreadAbstraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,17 @@ internal static class ThreadAbstraction
/// <param name="millisecondsTimeout">The number of milliseconds for which the thread is suspended.</param>
public static void Sleep(int millisecondsTimeout)
{
#if FEATURE_THREAD_SLEEP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid you'll need to revert these changes. Thread.Sleep(...) is not available for UAP10.0 TFM (see https://github.com/sshnet/SSH.NET/wiki/Conditional-compilation-symbols for more information).

System.Threading.Thread.Sleep(millisecondsTimeout);
#elif FEATURE_THREAD_TAP
System.Threading.Tasks.Task.Delay(millisecondsTimeout).GetAwaiter().GetResult();
#else
#error Suspend of the current thread is not implemented.
#endif
}

public static void ExecuteThreadLongRunning(Action action)
{
#if FEATURE_THREAD_TAP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to leave this as is. Eventually, we'll need to change this as we need the thread or task that we started for our message listener in order to avoid thread leaks (there's an issue for this).

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();
#endif
if (action == null)
throw new ArgumentNullException("action");
new System.Threading.Thread(() => action())
{
IsBackground = true
}.Start();
}

/// <summary>
Expand All @@ -36,16 +29,10 @@ public static void ExecuteThreadLongRunning(Action action)
/// <param name="action">The action to execute.</param>
public static void ExecuteThread(Action action)
{
#if FEATURE_THREAD_THREADPOOL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid you'll need to revert these changes. ThreadPool is not available for UAP10.0 TFM (see https://github.com/sshnet/SSH.NET/wiki/Conditional-compilation-symbols for more information).

if (action == null)
throw new ArgumentNullException("action");

System.Threading.ThreadPool.QueueUserWorkItem(o => action());
#elif FEATURE_THREAD_TAP
System.Threading.Tasks.Task.Run(action);
#else
#error Execution of action in a separate thread is not implemented.
#endif
}
}
}
3 changes: 2 additions & 1 deletion src/Renci.SshNet/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down