Last active
July 29, 2021 15:52
-
-
Save mahldcat/ab471cd1bf99e6c5461f4800f0db8e3c to your computer and use it in GitHub Desktop.
Skeletal example of using the async/await pattern.....
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [HttpPost("urlParam")] | |
| public async Task<MyResponse> PostAsync(string urlParam, [FromQuery] string arg2, [FromBody] MyBody parsableBodyData) | |
| { | |
| MyResponse mr = new MyResponse(); | |
| List<Task> tasks = new List<Task>(); | |
| foreach(IWorkerTask w in workList){ | |
| tasks.Add(w.DoWorkAsync(...).ContinueWith((task)=>{ | |
| //handle post processing from task.... | |
| //task.Result will contain the return value of the async | |
| mr.Result.Add(taskResult); | |
| })); | |
| } | |
| Task.AwaitAll(tasks.ToArray()); | |
| return mr; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment