提交 4e7a5531 编写于 作者: J Jared Parsons

Merge pull request #6307 from jaredpar/rmpw

Actually delete PumpingWait
......@@ -13,67 +13,10 @@ namespace Roslyn.Test.Utilities
{
public static class WaitHelper
{
/// <summary>
/// This is a hueristic for checking to see if we are in a deadlock state because
/// we are waiting on a Task that may be in the StaTaskScheduler queue from the
/// main thread.
/// </summary>
/// <param name="tasks"></param>
private static void CheckForStaDeadlockInPumpingWait(IEnumerable<Task> tasks)
{
var sta = StaTaskScheduler.DefaultSta;
Debug.Assert(sta.Threads.Length == 1);
if (Thread.CurrentThread != sta.Threads[0])
{
return;
}
if (tasks.Any(x => x.Status == TaskStatus.WaitingForActivation) && sta.IsAnyQueued())
{
throw new InvalidOperationException("PumingWait is likely in a deadlock");
}
}
public static void WaitForDispatchedOperationsToComplete(DispatcherPriority priority)
{
Action action = delegate { };
new FrameworkElement().Dispatcher.Invoke(action, priority);
}
public static void PumpingWait(this Task task)
{
PumpingWaitAll(new[] { task });
}
public static T PumpingWaitResult<T>(this Task<T> task)
{
PumpingWait(task);
return task.Result;
}
public static void PumpingWaitAll(this IEnumerable<Task> tasks)
{
var smallTimeout = TimeSpan.FromMilliseconds(10);
var taskArray = tasks.ToArray();
var done = false;
while (!done)
{
done = Task.WaitAll(taskArray, smallTimeout);
if (!done)
{
WaitForDispatchedOperationsToComplete(DispatcherPriority.ApplicationIdle);
CheckForStaDeadlockInPumpingWait(tasks);
}
}
foreach (var task in tasks)
{
if (task.Exception != null)
{
throw task.Exception;
}
}
}
}
}
\ No newline at end of file
......@@ -118,10 +118,5 @@ public void EnableActiveTokenTracking(bool enable)
waiter.Value.TrackActiveTokens = enable;
}
}
public void PumpingWait(Task task)
{
task.PumpingWait();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册