c# - I thought await continued on the same thread as the caller, but it seems not to -


I thought there was a point / wait about the asyn that when the work is done, the same reference Continuity is on

  Debug. WrightLine ("2: Thread ID:" +++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++ Thread.CurrentThread.ManagedThreadId); Wait fs.ReadAsync (data, 0, (int) fs.Length); Debug. WrightLine ("3: Thread ID:" + Thread. Current ReFread.ManageTrad ID);  

I did not expect this:

  2: thread ID: 10 3: thread ID: 11  

what gives? Why is thread ID different from UI threads?

According to [k] I have to call the configured Wipe to change the behavior of continuity!

when you wait , by default wait operator will use the current "capture context" and the async method to start over again.

This "reference" is SynchronizationContext.Current as long as it's null , in which case it Task Scheduler Current is . (If there is no currently running work, TaskScheduler.Current similarly TaskScheduler.Default , is the thread pool task scheduler).

It is important to note that Synchronization Contact or Task Scheduler does not necessarily indicate a special thread is a UI Synchronization Contex will schedule work on the UI thread; But ASP .NET Synchronization contaxes will not work on any particular thread.

I suspect that the reason for your problem is that you code async very soon when an application starts up, there is a plain old regular thread in it. This thread only becomes the UI thread when something like Application.Run .


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -