Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Web;
- using System.Web.Mvc;
- namespace WebApplication1.Controllers
- {
- public class HomeController : Controller
- {
- public async Task<ActionResult> Index()
- {
- await MyMethod();
- return View();
- }
- public async Task MyMethod()
- {
- Debug.WriteLine(SynchronizationContext.Current); // AspNetSyncronizationContext
- SynchronizationContext.SetSynchronizationContext(new CustomSyncContext());
- Debug.WriteLine(SynchronizationContext.Current); // WebApplication1.Controllers.HomeController.CustomSyncContext
- await SomeAsyncMethod().ConfigureAwait(true);
- Debug.WriteLine(SynchronizationContext.Current); //null
- }
- public async Task SomeAsyncMethod()
- {
- await Task.Delay(TimeSpan.FromSeconds(5));
- }
- public class CustomSyncContext : SynchronizationContext { }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement