C#
C#

help

Root Question Message

Atakan / Cracker
Atakan / Cracker12/14/2022
❔ 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
Atakan / Cracker
Atakan / Cracker12/14/2022
Callstack is as listed below
Atakan / Cracker
Atakan / Cracker12/14/2022
1 (here calling logger.log without await keyword but the service calls this method is still waiting)
Atakan / Cracker
Atakan / Cracker12/14/2022
2
Atakan / Cracker
Atakan / Cracker12/14/2022
3
Atakan / Cracker
Atakan / Cracker12/14/2022
4
Atakan / Cracker
Atakan / Cracker12/14/2022
Sorry for images, I am on VPN
Atakan / Cracker
Atakan / Cracker12/14/2022
1 -> 2 -> 3 -> 4
Angius
Angius12/14/2022
One thing that comes to mind is perhaps explicitly disposing the task?
Angius
Angius12/14/2022
_ = FireAndForgetAsync()
Atakan / Cracker
Atakan / Cracker12/14/2022
I am not sure how does disposing task works, don't think I have similar operation
Atakan / Cracker
Atakan / Cracker12/14/2022
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
Atakan / Cracker
Atakan / Cracker12/14/2022
I have debugged the bulk insert method without using Task.Factory.StartNew and it behave the same
Atakan / Cracker
Atakan / Cracker12/14/2022
There is a method resizing request data for optimize space on database, that operation cpu bound work
Atakan / Cracker
Atakan / Cracker12/14/2022
I replaced that method with Task.Delay and it works properly now
Atakan / Cracker
Atakan / Cracker12/14/2022
I can't see why
phaseshift
phaseshift12/14/2022
You replaced some code you didn't show here?
phaseshift
phaseshift12/14/2022
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'
Atakan / Cracker
Atakan / Cracker12/14/2022
That's right, there is long running cpu bound sync operation inside await PrepareData 4th image
Atakan / Cracker
Atakan / Cracker12/14/2022
thats where I replaced with await Task.Delay
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy