Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Another title could be 'How to make an async Repository pattern with image upload in ASP.NET 5'

I'm making a site with ASP.NET 5 and it uses the CSOM (ClientContext, etc) to connect to a Sharepoint Online server. If the user has uploaded an image (to a Web API) it needs to be placed on the Sharepoint.

the request currently takes too long if everything is synchronous. (6-7 seconds) but I have several solutions for async. However I feel some of them are not entirely idiomatic and I want to pick the best solution.

I want the image upload to be 'fire and forget' since in this case I don't care if it worked or not, but I have no idea where I should start placing async/await.

Should I make the entire thing async and start from Web API method? I feel this is unnecessary because as I said I'm not looking for the result of the upload. I'm using a Repository and Context design pattern, should async only be placed in the repository? Can I just place it in the context?

Also should I avoid Task.Run() and other 'unregistered' background workers for this action? I read that these threads can be lost because of runtime cleanup but I don't know if I should avoid them entirely for such a small task of 1-2 seconds.

Also, should I ignore the CS4014 warning if I do this or would it be better to let it stay?

CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.