-
-
Notifications
You must be signed in to change notification settings - Fork 963
Start MessageListener with ThreadAbstraction.ExecuteThreadLongRunning #901
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
Changes from all commits
7aa2521
cd69534
5d173c8
a47f703
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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).