Call webservice asynchronously and wait for all threads to be finished

后端 未结 3 1544
情话喂你
情话喂你 2021-01-24 12:04

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         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-24 12:38

    This would initiate asynchronous call

     public delegate IList SaveToDb(IList myParam);
     SaveToDb _saveToDb= new SaveToDb(objService.SaveToDb);
     IAsyncResult asyncSearchResult = saveToDb.BeginInvoke(input,null,null)
    

    This would wait for execution to complete and return value:-

    IList result=asyncSearchResult EndInvoke();
    

提交回复
热议问题