3
I have the following method:
public string MyMethod1(string myParam1) {
// Implementação
return myReturnValue;
}
I needed to create an asynchronous method that did the same thing, to process several items from a list at the same time, so I created a second method as follows:
public async Task<string> MyMethod1Async(string myParam1) {
return MyMethod1(myParam1);
}
Visual Studio complained that I’m not using the operator await
in an asynchronous method. But basically I’m repurposing the method that already existed and creating an asynchronous alternative that I call as follows:
var myResult = Task.WhenAll(myStringList.Select(myStringItem => MyMethod1Async(myStringItem)).Result;
I used a
string
for the parameter only as a simplified example.The synchronous method should continue to exist in the same way.
1. This way the objects in the actual list will be being processed to the same time?
2. Is there any more appropriate way to implement a method asynchronous in this context?
Have you looked at
Task.FromResult<>
will already solve your immediate problem, I do not know if you have something else, but, I believe that would solve– novic
I didn’t know no @Virgilionovic , but I’ll take a look here right now. Thank you so much!
– Jedaias Rodrigues