/// <summary> /// Get preferred discount (with maximum discount value) /// </summary> /// <param name="discounts">A list of discounts to check</param> /// <param name="amount">Amount (initial value)</param> /// <param name="discountAmount">Discount amount</param> /// <returns>Preferred discount</returns> public virtual List<Discount> GetPreferredDiscount(IList<Discount> discounts, decimal amount, out decimal discountAmount)
This routine does not need to be Synchronous because all it does is some calculations, record manipulation and the routines it calls i.e. GetDiscountAmount(...) are also Synchronous. i.e. it does not call any async routines and everything runs in realtime
In fact if you changed it to be an async routine then the compiler will provide the warning warning CS1998: This async method lacks 'await' operators and will run synchronously.
/// <summary> /// Get preferred discount (with maximum discount value) /// </summary> /// <param name="discounts">A list of discounts to check</param> /// <param name="amount">Amount (initial value)</param> /// <param name="discountAmount">Discount amount</param> /// <returns>Preferred discount</returns> public virtual List<Discount> GetPreferredDiscount(IList<Discount> discounts, decimal amount, out decimal discountAmount)
This routine does not need to be Synchronous because all it does is some calculations, record manipulation and the routines it calls i.e. GetDiscountAmount(...) are also Synchronous. i.e. it does not call any async routines and everything runs in realtime
In fact if you changed it to be an async routine then the compiler will provide the warning warning CS1998: This async method lacks 'await' operators and will run synchronously.
Without making the inner method async we can not use await operator. so for the inner method, we can write something like await Task.FromResult(whateverthevalue); and then call it from the main method by await operator.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.