My question is involving a web api I created using asp.net/c# and is deployed to an Azure server. The API basically gets a requests to process an image with some text printed over it.
I have a method that is called once a get request is received. In english, the method does some setup, then downloads the proper image requested from Azure blob storage, then does the drawing.
public HttpResponseMessage process(string image){
DoSomeSetup();
DownloadFromBlob(image);
return DrawTextOnImage();
}
My problem is that downloading from the Azure blob takes the longest time out of all the operations, usually 2-3 seconds. I figure that it would be much more efficient if I could download the image WHILE setup is occurring, in order to save time.
public HttpResponseMessage process(string image){
startDownloadingImageFromBlob(image);
DoSomeSetup();
EnsureImageDownloadFinished();
return DrawTextOnImage();
}
I am under the impression that simply calling
Bitmap templateImage = DownloadImageFromUrl(BLOB_STORAGE_TEMPLATES_BASE_URL)
at the top of the method will wait for the download to complete before moving onto the setup. Is there a way that I can get the download to happen at the same time as setup, and then (if necessary) wait for it to finish before drawing?