Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TestController : ApiController
- {
- // This method must be synchronous
- public void Test()
- {
- Debug.WriteLine($"Main Thread {Thread.CurrentThread.ManagedThreadId}");
- // I must use a Task here because otherwise I will have to block async code which will cause a deadlock
- var task = Task.Run(() =>
- {
- Debug.WriteLine($"Child Thread {Thread.CurrentThread.ManagedThreadId}");
- SomeAsynchronousWork().GetAwaiter().GetResult();
- });
- task.GetAwaiter().GetResult();
- }
- public async Task SomeAsynchronousWork()
- {
- // some work that must be done asynchronously
- }
- }
- Main Thread 5
- Child Thread 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement