Home >Backend Development >C++ >Task.Run vs. Async-Await: When Should You Use Which for Optimal Performance?
In the application design, it is important to correctly use Task.run and Async-Await, which directly affects performance and UI response speed.
Async-AWait Keep UI response
The asynchronous programming using Async-Await can avoid blocking UI threads and achieve it by uninstalling the task to the thread pool. This keeps the UI respond during task execution. However, it should be noted that if the configureawait (false) is not explicitly used, the asynchronous method may still be executed on the UI thread.
task.run for the CPU dense task
Task.run provides a convenient way to entrust the CPU dense operation to the thread pool, clearly uninstall them from the UI thread. This is particularly beneficial for the task of performing a large amount of computing or operating large data sets, because these tasks may lead to UI lag. Best Practice Guide
When selecting task.run and Async-Await, consider the following criteria:
Follow these criteria, you can optimize the performance of the WPF application while maintaining the response ability of the UI.
The above is the detailed content of Task.Run vs. Async-Await: When Should You Use Which for Optimal Performance?. For more information, please follow other related articles on the PHP Chinese website!