I need to call the web service several times to get data, and then put those data into my database, so I've got the following code:
foreach (string v in options)
{
IList<MySampleNode> nodes = _pi.GetData(v);
_dbService.SaveToDb(nodes);
}
the GetData implementation looks as follows:
public IList<MySampleNode> GetData(string v)
{
IList<MySampleNode> nodes = null;
try
{
var client = new WsClient();
IEnumerable<IWsObject> wsNodes = client.getNodes(new getClassLevel { code = v });
nodes = ProcessData(wsNodes);
}
return nodes;
}
I'd like to modify this code to asynchronous version to run each download/save to database in separate thread and wait for all threads to be finished, or maybe there are some other approaches to improve the performance of such code, can you please help me?