Skip to content

Commit d087776

Browse files
Avoid deadlock possibility
1 parent c10f05e commit d087776

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

CodeConverter/Common/EnumerableExtensions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.ObjectModel;
2+
using Microsoft.VisualStudio.Threading;
23

34
namespace ICSharpCode.CodeConverter.Common;
45

@@ -90,7 +91,13 @@ public static IEnumerable<T> Yield<T>(this T singleElement)
9091
yield return singleElement;
9192
}
9293

93-
public static async Task<IEnumerable<T>> YieldAsync<T>(this Task<T> task) => (await task).Yield();
94+
public static async Task<IEnumerable<T>> YieldAsync<T>(this Task<T> task)
95+
{
96+
await TaskScheduler.Default;
97+
#pragma warning disable VSTHRD003 // Avoid awaiting foreign Tasks - We've just switched away from the main thread so can't deadlock
98+
return (await task).Yield();
99+
#pragma warning restore VSTHRD003 // Avoid awaiting foreign Tasks
100+
}
94101

95102
public static IEnumerable<T> YieldNotNull<T>(this T singleElement)
96103
{

0 commit comments

Comments
 (0)