/ Published in: C#
Make an existing calculation intensive method asynchronous.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public class ClassContainingCalculationIntensiveCode { public double SomeCalculation() { // code omitted } // NOTE: Returning a new task object encapsulating the calculation is all that's needed. // The consuming code needs to use async/await keywords. public Task<double> SomeCalculationAsync() { return Task.Factory.StartNew(() => { return SomeCalculation(); }); } }