Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
tosensei837594dthat's a very bad example of using task.run. the operation inside takes significantly less time than the task-scheduling overhead.
if anything, you should use `Interlocked.Increment(age)` to make it 100% thread safe. -
donkulator288494d@tosensei Hmm. Based on that, I might have to approach this from a completely different angle:
using var age = serviceContainer.GetService<IAge>();
using var rpot = serviceContainer.GetService<IRelentlessPassageOfTime>();
rpot.Advance(age); -
tosensei837594d@donkulator or as alterative:
Environment.DisableBotheringAboutCompletelyMeaninglessSocialConventions(); -
Ranchonyx1064394dqueueMicrotask(() => globalThis.age++);
This is a safe way, it executes after all pending tasks have been executed.
await Task.Run(() => { age++; });
rant