I have a question regarding some code I am writing. I have 3 calls made synchronously to some endpoints that have large payloads. I don’t want to wait for these payloads and instead continue running through the method until I need the values from those 3 endpoints.
I have approached a solution like this. I converted the method that calls the 3 service endpoints into an async method. I start the call for the data using
var serviceCallOneTask = Task.Run(()=> serviceCallOne());
Note serviceCallOne() is not asynchronous and finally when I need the data I do something like
var serviceCallOneValue = await serviceCallOneTask;
My questions are
- Is this solution considered bad practice?
- Should I be worried about deadlocks?
- From what I have read, when using await we are not blocking a thread but when using task.run we are using a CPU-bound thread and we are blocking the thread pool; is that correct?
- Is it better for me to convert everything in this httpGet method from beginning to end into async methods?
- Is it ok for me to approach the problem this way for now and later on convert those task.run() services into asynchronous methods?