< Summary

Information
Class: Renci.SshNet.Abstractions.ThreadAbstraction
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Abstractions\ThreadAbstraction.cs
Line coverage
61%
Covered lines: 11
Uncovered lines: 7
Coverable lines: 18
Total lines: 53
Line coverage: 61.1%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
Sleep(...)100%10%
ExecuteThreadLongRunning(...)50%277.77%
ExecuteThread(...)50%266.66%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Abstractions\ThreadAbstraction.cs

#LineLine coverage
 1using System;
 2using System.Threading;
 3using System.Threading.Tasks;
 4
 5namespace Renci.SshNet.Abstractions
 6{
 7    internal static class ThreadAbstraction
 8    {
 9        /// <summary>
 10        /// Suspends the current thread for the specified number of milliseconds.
 11        /// </summary>
 12        /// <param name="millisecondsTimeout">The number of milliseconds for which the thread is suspended.</param>
 13        public static void Sleep(int millisecondsTimeout)
 014        {
 015            Thread.Sleep(millisecondsTimeout);
 016        }
 17
 18        /// <summary>
 19        /// Creates and starts a long-running <see cref="Task"/> for the specified <see cref="Action"/>.
 20        /// </summary>
 21        /// <param name="action">The <see cref="Action"/> to start.</param>
 22        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <see langword="null"/>.</exception>
 23        /// <returns>
 24        /// A task that represents the execution of the specified <see cref="Action"/>.
 25        /// </returns>
 26        public static Task ExecuteThreadLongRunning(Action action)
 181727        {
 181728            if (action is null)
 029            {
 030                throw new ArgumentNullException(nameof(action));
 31            }
 32
 181733            return Task.Factory.StartNew(action,
 181734                                         CancellationToken.None,
 181735                                         TaskCreationOptions.LongRunning,
 181736                                         TaskScheduler.Current);
 181737        }
 38
 39        /// <summary>
 40        /// Executes the specified action in a separate thread.
 41        /// </summary>
 42        /// <param name="action">The action to execute.</param>
 43        public static void ExecuteThread(Action action)
 367244        {
 367245            if (action is null)
 046            {
 047                throw new ArgumentNullException(nameof(action));
 48            }
 49
 734450            _ = ThreadPool.QueueUserWorkItem(o => action());
 367251        }
 52    }
 53}