In .Net web service you can set application level variables like this
application("Stackoverflow") = "Stack"
application("Serverfault") = "Server"
If you receive multiple requests, you can simply lock, then update, then unlock
try
application.lock()
application("Serverfault") = "Fault"
finally
application.unlock()
end try
Now, this locks all the application variables, is there a way to just lock a single application variable? Instead of all the application variables at once?
Interestingly enough, I had a different issue I was researching, which I think provides me a solution the question I posted.
This:
Using mutex = New Mutex(False, "LockServerFault")
mutex.WaitOne()
application("ServerFault") = "Fault"
mutex.ReleaseMutex()
End Using
Accomplishes the same thing as:
try
application.lock()
application("Serverfault") = "Fault"
finally
application.unlock()
end try
But it doesn't lock all application variables, but it does prevent the single application variable from being updated at the same time. This enables me to update different application variables in different threads, without making all threads pause for application variables that don't apply to them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With