Mark TaskSyncExtensions methods as obsolete
The `TaskSyncExtensions` class and its methods (`Sync` and `Sync<TResult>`) have been marked as `[System.Obsolete]`. These methods are no longer recommended due to the risk of deadlocks and unexpected behavior caused by synchronous blocking. Developers are advised to use `async/await` patterns instead. The warning messages indicate that these methods will be removed in a future release.
This commit is contained in:
@@ -7,12 +7,14 @@ namespace ReC.Client
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides synchronous wrappers for Task-based operations.
|
/// Provides synchronous wrappers for Task-based operations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[System.Obsolete("Synchronous blocking helpers (Task.Sync) are no longer recommended. These methods can cause deadlocks or unexpected behavior. Rewrite calling code to use async/await (e.g. async Task tests). This helper class will be removed in a future release.", false)]
|
||||||
public static class TaskSyncExtensions
|
public static class TaskSyncExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Blocks until the task completes and propagates any exception.
|
/// Blocks until the task completes and propagates any exception.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="task">The task to wait for.</param>
|
/// <param name="task">The task to wait for.</param>
|
||||||
|
[System.Obsolete("Use async/await instead of synchronous blocking. This method can cause deadlocks.", false)]
|
||||||
public static void Sync(this Task task) => task.ConfigureAwait(false).GetAwaiter().GetResult();
|
public static void Sync(this Task task) => task.ConfigureAwait(false).GetAwaiter().GetResult();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -21,6 +23,7 @@ namespace ReC.Client
|
|||||||
/// <typeparam name="TResult">The type of the task result.</typeparam>
|
/// <typeparam name="TResult">The type of the task result.</typeparam>
|
||||||
/// <param name="task">The task to wait for.</param>
|
/// <param name="task">The task to wait for.</param>
|
||||||
/// <returns>The result of the completed task.</returns>
|
/// <returns>The result of the completed task.</returns>
|
||||||
|
[System.Obsolete("Use async/await instead of synchronous blocking. This method can cause deadlocks.", false)]
|
||||||
public static TResult Sync<TResult>(this Task<TResult> task) => task.ConfigureAwait(false).GetAwaiter().GetResult();
|
public static TResult Sync<TResult>(this Task<TResult> task) => task.ConfigureAwait(false).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user