c# - How to run 2 async functions simultaneously -
i need know how run 2 async functions simultaneously, example check following code:
public async task<responsedatamodel> datadownload() {   responsedatamodel responsemodel1 = await requestmanager.createrequest(postdata);   responsedatamodel responsemodel2 = await requestmanager.createrequest(postdata);    //wait here till both tasks complete. return result.  } here have 2 createrequest() methods runs sequentially. run these 2 functions parallel , @ end of both functions want return result. how achieve this?
if need first result out of 2 operations can calling 2 methods, , awaiting both tasks `task.whenany:
public async task<responsedatamodel> datadownloadasync() {     var completedtask = await task.whenany(         requestmanager.createrequest(postdata),          requestmanager.createrequest(postdata));     return await completedtask; } task.whenany creates task complete when first task of of supplied tasks completed. returns 1 task completed can result. 
Comments
Post a Comment