.NET 3.5 C# does not offer what I need for locking: Count async saves until 0 again.
Posted
by Frank Michael Kraft
on Stack Overflow
See other posts from Stack Overflow
or by Frank Michael Kraft
Published on 2010-04-23T18:12:12Z
Indexed on
2010/04/23
19:23 UTC
Read the original article
Hit count: 257
I have some records, that I want to save to database asynchronously. I organize them into batches, then send them. As time passes, the batches are processed.
In the meanwhile the user can work on. There are some critical operations, that I want to lock him out from, while any save batch is still running asynchronously.
The save is done using a TableServiceContext and method .BeginSave() - but I think this should be irrelevant.
What I want to do is whenever an async save is started, increase a lock count, and when it completes, decrease the lock count so that it will be zero as soon as all have finished. I want to lock out the critical operation as long as the count is not zero. Furthermore I want to qualify the lock - by business object - for example.
I did not find a .NET 3.5 c# locking method, that does fulfil this requirement. A semaphore does not contain a method to check, if the count is 0. Otherwise a semaphore with unlimited max count would do.
© Stack Overflow or respective owner