locked
Is LightSwitch compatible with UseTaskFriendlySynchronizationContext? RRS feed

  • Question

  • I've followed Beth Massi's instructions for enabling .NET 4.5 in a LightSwitch 2012 Update 2 application. I'm also integrating a Web Api endpoint in the server project, and this controller needs to do an async/await operation.

    After the await statement, HttpContext.Current is null, which means I can't create a LightSwitch context, as explained by this exception:

    A server application context cannot be created from a thread that does not have a HTTP context (HttpContext.Current must not be null).

    Now, if I enable UseTaskFriendlySynchronizationContext like this:

    <appSettings>
       <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    </appSettings>

    Then HttpContext.Current is preserved and the LightSwitch calls works.

    My question is: does LightSwitch support UseTaskFriendlySynchronizationContext=true? Is it compatible?

    I ask this because there are reports that this setting can lead to issues such as deadlocks. For instance: 

    http://vegetarianprogrammer.blogspot.com.br/2012/12/understanding-synchronizationcontext-in.html

    Since this setting changes the task scheduler's behavior, a simple test on my machine is unlikely to catch complex situations that could happen in a server under load.


    Fernando Correia
    pensandoazure.wordpress.com
    @facorreia


    Saturday, June 15, 2013 2:17 PM

All replies