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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -