Skip to content

Commit ed86689

Browse files
committed
Use better timeout mechanism, force task onto new thread
1 parent 8d755e2 commit ed86689

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

test/PowerShellEditorServices.Test/Language/LanguageServiceTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,12 @@ internal static class TaskExtensions
420420
{
421421
public static async Task<T> RunWithTimeout<T>(this Task<T> task, int timeoutMillis = 10000)
422422
{
423-
if (await Task.WhenAny(task, Task.Delay(timeoutMillis)) == task)
423+
Task<T> newThreadTask = Task<T>.Run(() => task);
424+
if (!((IAsyncResult)newThreadTask).AsyncWaitHandle.WaitOne(timeoutMillis))
424425
{
425-
return task.Result;
426+
throw new TimeoutException();
426427
}
427-
428-
throw new TimeoutException();
428+
return await newThreadTask;
429429
}
430430
}
431431
}

0 commit comments

Comments
 (0)