All i want to use Out keyword with my Async function. According to MSDN it is not possible Async modifiers not supports to the out keyword. So is there any alternate in .Net framework 4.5/4.0 ?
The async keyword turns a method into an async method, which allows you to use the await keyword in its body. When the await keyword is applied, it suspends the calling method and yields control back to its caller until the awaited task is complete. await can only be used inside an async method.
The call to the async method starts an asynchronous task. However, because no Await operator is applied, the program continues without waiting for the task to complete. In most cases, that behavior isn't expected.
The warning is exactly right: if you mark your method async but don't use await anywhere, then your method won't be asynchronous. If you call it, all the code inside the method will execute synchronously.
You can declare the async function to return Tuple
instead. With that the function still able to return multiple values without using out
parameter.
public async Task<Tuple<string, int, bool>>SomeFunctionAsync()
{
return new Tuple<string, int, bool>("foo", 0, false);
}
For Reference :
UPDATE :
you can use shorter syntax as suggested by @svick in comment. Following function return the same value, but using Tuple.Create
:
public async Task<Tuple<string, int, bool>>SomeFunctionAsync()
{
return Tuple.Create("foo", 0, false);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With