Last active
September 20, 2023 08:09
-
-
Save in-async/15dc92d104a1d8733fb3e0c1b0b71f17 to your computer and use it in GitHub Desktop.
`TaskCompletionSource<T>` でデッドロックする例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TaskCompletionSource<object?> tcs = new( | |
// NOTE: RunContinuationsAsynchronously を付けるとデッドロックしない(非同期に継続される) | |
// TaskCreationOptions.RunContinuationsAsynchronously | |
); | |
ManualResetEventSlim mre = new(); | |
_ = Task.Run(() => { | |
Console.WriteLine("Start background"); | |
tcs.TrySetResult(null); // 2 | |
mre.Set(); // (4) | |
Console.WriteLine("End background"); | |
}); | |
await tcs.Task.ConfigureAwait(false); // 1 | |
mre.Wait(); // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
関連記事