C
C#2y ago
Cracker

❔ 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
Cracker
CrackerOP2y ago
Callstack is as listed below
Cracker
CrackerOP2y ago
1 (here calling logger.log without await keyword but the service calls this method is still waiting)
Cracker
CrackerOP2y ago
2
Cracker
CrackerOP2y ago
3
Cracker
CrackerOP2y ago
4
Cracker
CrackerOP2y ago
Sorry for images, I am on VPN 1 -> 2 -> 3 -> 4
Angius
Angius2y ago
One thing that comes to mind is perhaps explicitly disposing the task? _ = FireAndForgetAsync()
Cracker
CrackerOP2y ago
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
phaseshift
phaseshift2y ago
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'
Cracker
CrackerOP2y ago
That's right, there is long running cpu bound sync operation inside await PrepareData 4th image thats where I replaced with await Task.Delay
Accord
Accord2y ago
Was 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.
Want results from more Discord servers?
Add your server