I recently had the need to add an asynchronous variant of the lock
keyword to one of my applications. There are many implementations to choose from, but the two that most appealed to me were:
- AsyncLock from the AsyncEx library.
Main reason: It's from a widely used library. - Scott Hanselman's AsyncLock which is based on Stephen Toub's AsyncLock
Main reason: It's very simple and I can just paste it into my project without needing a new library.
What are the differences during runtime for the two solutions?
Of course the AsyncEx AsyncLock has more features, but assuming I don't need those, how do the two compare?
CancellationToken
support? Just a bare-boneWaitAsync
with no arguments and nothing else? – Demonize