Почему ExecuteSynchronous не используется по умолчанию для асинхронного ожидания? ⇐ C#
-
Anonymous
Почему ExecuteSynchronous не используется по умолчанию для асинхронного ожидания?
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
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
Мобильная версия