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 multiple items in 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 was not using the await
operator in an asynchronous method. But basically I'm reusing the existing method and creating an asynchronous alternative that I call the following way:
var myResult = Task.WhenAll(myStringList.Select(myStringItem => MyMethod1Async(myStringItem)).Result;
I used a% w of% for the parameter only as a simplified example.
Synchronous method should continue to exist in the same way.
1. This way the objects in the list will in fact be processed same time?
2. Is there any more appropriate way to implement a method asynchronous in this context?