feat: Added ThreadingUtils overloads

This commit is contained in:
Chris Cameron
2021-05-24 10:11:49 -04:00
parent 8b848e5127
commit e6dec641f3

View File

@@ -22,7 +22,7 @@ namespace ICD.Common.Utils
private static readonly SafeCriticalSection s_ThreadsSection; private static readonly SafeCriticalSection s_ThreadsSection;
/// <summary> /// <summary>
/// Static contstructor. /// Static constructor.
/// </summary> /// </summary>
static ThreadingUtils() static ThreadingUtils()
{ {
@@ -30,6 +30,17 @@ namespace ICD.Common.Utils
s_ThreadsSection = new SafeCriticalSection(); s_ThreadsSection = new SafeCriticalSection();
} }
/// <summary>
/// Wait until the given condition is true.
/// </summary>
/// <param name="condition"></param>
/// <param name="timeout"></param>
/// <returns>False if the call times out</returns>
public static bool Wait(Func<bool> condition, TimeSpan timeout)
{
return Wait(condition, (long)timeout.TotalMilliseconds);
}
/// <summary> /// <summary>
/// Wait until the given condition is true. /// Wait until the given condition is true.
/// </summary> /// </summary>
@@ -52,6 +63,15 @@ namespace ICD.Common.Utils
return true; return true;
} }
/// <summary>
/// Puts the current thread to sleep for the given amount of time.
/// </summary>
/// <param name="duration"></param>
public static void Sleep(TimeSpan duration)
{
Sleep((int)duration.TotalMilliseconds);
}
/// <summary> /// <summary>
/// Puts the current thread to sleep for the given amount of time. /// Puts the current thread to sleep for the given amount of time.
/// </summary> /// </summary>