c# - ContinueWith loses the SynchronizationContext -
In the snippet below, This output is: before GetAsync; Thread: 56, Reference: ASPNet Syntax ContacTech, Culture: NL, Uriculture: NL. Prior to What I think, everything should be happening To determine continuity on the reference thread, you can type However, you are waiting for SynchronizationContext is lost, and this also causes
current culture < / code> and
current uk agriculture . Comes from
log () .
Public async Tasks & lt; ActionResult & gt; Index () {log ("before GetAsync"); Wait for the new HTTP client (). Continue GetAsync ("http://www.example.com/"). (Request = & gt; {Log ("Continue"); Request.InstructiveStatusSod ();}, Task Continuation Options. Attachtipant); See Return (); } Fixed zero log (string message) {var ctx = System.Threading.SynchronizationContext.Current; System.Diagnostics.Debug.Print ("{0}; Thread: {1}, Reference: {2}, Culture: {3}, Native Language: {4}", Message, System Threading Thread.Centrethread.ManagedTride, Ctx! = Null? Ctx.GetType () .name: string.optim; system threading thread.contentrath.contentculture.Name, system threading thread.contentthread.correntcurrent.name); }
GetAsync , the values I have defined in culture and UI culture are in I
Application_BeginRequest . Inside
Continue , the context is missing, the culture is set to things provided by the browser, and the UI culture is set to some default.
aspNetSynchronizationContext automatically, what's wrong with my code?
task scheduler Need to be specified, which should be used when determining continuity.
Public async Tasks & lt; ActionResult & gt; Index () {log ("before GetAsync"); Wait for the new HTTP client (). Continue GetAsync ("http://www.example.com/"). (Request = & gt; {Log ("Continue"); Request.Result.EnsureSuccessStatusCode ();}, Task Continuation Options. Attachepatent, Cancellation Token.No, Task Scheduler. From Content Synchronization Contex ()); See Return (); }
, which currently continues on
Public ASINC works & lt; Action & gt; Index () {log ("before GetAsync"); HttpResponseMessage Request = Waiting for new HTTP client () GetAsync ("http://www.example.com/"); // Below everything below is the 'continuation' on the reference log ("Continue"); Request.EnsureSuccessStatusCode (); See Return (); }
Comments
Post a Comment