❔ Async Await On Logging - Waiting Response Without Await Keyword
I have logging service where I call the logger.log async method without awaiting the response, expected behaviour is that the method calls logger.log will return the response without await the log response, but its otherwise
11 Replies
Callstack is as listed below
1 (here calling logger.log without await keyword but the service calls this method is still waiting)
2
3
4
Sorry for images, I am on VPN
1 -> 2 -> 3 -> 4
One thing that comes to mind is perhaps explicitly disposing the task?
_ = FireAndForgetAsync()
I am not sure how does disposing task works, don't think I have similar operation
We have old SQL Bulk Insert code, there used Task.Factory.StartNew for each log item. I haven't use it here but still If I dont await the async task then it should behave fire and forget way
I have debugged the bulk insert method without using Task.Factory.StartNew and it behave the same
There is a method resizing request data for optimize space on database, that operation cpu bound work
I replaced that method with Task.Delay and it works properly now
I can't see why
You replaced some code you didn't show here?
Adding in a task.Delay is adding a point for the async state machine to start. Sounds like you were calling a lot of long running sync code before the first chance for the state machine to 'go async'
That's right, there is long running cpu bound sync operation inside
await PrepareData
4th image
thats where I replaced with await Task.DelayWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.