wasAsked.

public void Dowork(); public async Task PerformOperationAsync() { //Call here the //synchronous method //Dowork() //asynchronously; }

Mphasis · Role not specified · technical

Published

Year not specified · C#

Community answers

Posted by wasAsked editorial collection

Do not wrap naturally asynchronous I/O in Task.Run; expose and await its async API. Task.Run is appropriate mainly for CPU-bound or unavoidable blocking work that you intentionally move off a UI thread. Example: public Task<Result> DoWorkAsync(CancellationToken ct) => Task.Run(() => DoWork(ct), ct); In ASP.NET Core, Task.Run does not make blocking work scalable: it still consumes a thread-pool thread. Prefer replacing the synchronous dependency, or run long work in a bounded background queue and return a job identifier. Pass cancellation, observe exceptions, and never fire-and-forget request-scoped work.

Backbencher Developer · · 0 likes

Sign in to add your answer

Related interview topics