Почему ExecuteSynchronous не используется по умолчанию для асинхронного ожидания?C#

Место общения программистов C#
Ответить
Anonymous
 Почему ExecuteSynchronous не используется по умолчанию для асинхронного ожидания?

Сообщение Anonymous »


We know that if we uses async/await

await methodAsync(); var result = methodNonAsync() // ... await methodAsync() puts a item on the queue, so that a thread pool thread (says threadA) can execute this task.

and I would say it is optimized that threadA also execute var result = methodNonAsync().

But when I check the source code https://source.dot.net/#System.Private. ... d9262599b9 of ContinueWith (that's how async/await works behind the scene)

public Task ContinueWith(Action continuationAction) { return ContinueWith(continuationAction, TaskScheduler.Current, default, TaskContinuationOptions.None); } it uses TaskContinuationOptions.None not TaskContinuationOptions.ExecuteSynchronously, so it means another threadB from thread pool might executes `var result = methodNonAsync(), so this is an extra context switch.

so why ExecuteSynchronously is not the default option for async await usage for performance boost?


Источник: https://stackoverflow.com/questions/781 ... sync-await
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»