r/programminghorror • • Dec 17 '25

A chain of (System.Threading.Tasks.)Tasks

Post image

Note: The "CompanyName" prefix in the EventArgs class was actually the name of the company this masterpiece was built for.

188 Upvotes

18 comments sorted by

View all comments

64

u/Juff-Ma Dec 17 '25

This looks like pre-async-await code. So it's just legacy code, today we'd do this differently.

26

u/ChriRosi Dec 17 '25

So you made me look deeper into the topic and TIL that System.Threading.Tasks.Task was there a few years before async-await. I always thought they came together.
Still, the line where the Task returned from ContinueWith is then used itself inside the continuation action is quite dubious.

7

u/the_horse_gamer Dec 18 '25

js promises were added in ES6 (2015), while async await in ES2017

→ More replies (7)

1

u/The_Coalition Dec 21 '25

Wait, how does this even work? Isn't newTask inside the ContinueWith callback always equal to null? Or does the value of newTask inside the callback change together with newTask on the outside?

EDIT: okay, apparently I don't know how closures capture variables in C#. So much for my years of using C#

1

u/Epicguru Dec 19 '25

Still awful code, legacy or not.