I created an ASP WebApplication using Visual Studio 2012.If I modify the default page as follows:\[code\]public partial class _Default : Page{ static async Task PerformSleepingTask() { Action action = () => { Thread.Sleep(TimeSpan.FromSeconds(0.5)); int dummy = 3; // Just a nice place to put a break point }; await Task.Run(action); } protected void Page_Load(object sender, EventArgs e) { Task performSleepingTask = PerformSleepingTask(); performSleepingTask.Wait(); }}\[/code\]On the call to \[code\]performSleepingTask.Wait()\[/code\] it hangs indefinitely.Interestingly, if I set this in the web.config:\[code\]<appSettings> <add key="aspnet:UseTaskFriendlySynchronizationContext" value="http://stackoverflow.com/questions/12701879/false" /></appSettings>\[/code\]Then it does work. The \[code\]Wait\[/code\] function waits for the sleeping to finish on a different thread, then continues.Can somebody explain:
- Why does it hang?
- Why do they have something called \[code\]TaskFriendlySynchronizationContext\[/code\]? (More like \[code\]TaskUNFRIENDLYSynchronizationContext\[/code\])
- Is there a "best practice" for invoking \[code\]async\[/code\] methods from page handler methods?