c# - What's The Actual Difference Between await XXAsync() And await Task.Run(()=>{XX() } -
by using task.run
or task.factory.startnew
can convert synchronous actions tasks, can use await
, this:
await task.run(() => { somemethod(); }
in meantime, many methods have asynchronous implements, recommended directly use
await somemethodasync();
but what's difference between two?
somemethodasync
method io work , io work not require thread work. somemethodasync
not cause thread thread-pool sit , wait complete. thread-pool threads important resources in server application such asp.net applications. in such applications, each request serviced thread-pool thread , number of active requests can increased saving such threads.
await task.run(() => { somemethod(); }
uses thread-pool thread execute somemethod
method. if somemethod
io work, used thread-pool thread unnecessarily.
Comments
Post a Comment