I am loading up some values from my database to be displayed to my website users. Since these values won't be changing too much, I am loading them up into a static/shared object.
To ensure that multiple users aren't modifying this same object at the same time, I am using Monitor.Enter
(and Monitor.Exit
) to lock/block around the loading of these values.
Unfortunately, this does not work when being called from an MVC view in .NET as it throws this exception:
Object synchronization method was called from an unsynchronized block of code.
Is there a way to do this, via MVC, without completely changing my code design?