using System;
using System.Threading;
using System.Threading.Tasks;
namespace Renci.SshNet.Abstractions
{
internal static class ThreadAbstraction
{
///
/// Suspends the current thread for the specified number of milliseconds.
///
/// The number of milliseconds for which the thread is suspended.
public static void Sleep(int millisecondsTimeout)
{
Thread.Sleep(millisecondsTimeout);
}
///
/// Creates and starts a long-running for the specified .
///
/// The to start.
/// is .
///
/// A task that represents the execution of the specified .
///
public static Task ExecuteThreadLongRunning(Action action)
{
if (action is null)
{
throw new ArgumentNullException(nameof(action));
}
return Task.Factory.StartNew(action,
CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Current);
}
///
/// Executes the specified action in a separate thread.
///
/// The action to execute.
public static void ExecuteThread(Action action)
{
if (action is null)
{
throw new ArgumentNullException(nameof(action));
}
_ = ThreadPool.QueueUserWorkItem(o => action());
}
}
}