asp.net - How to refresh singleton in C# -


I have a singleton that gets from DB, so it is a costly load, it is full of laziness.

I would like to make a method that refreshes the singletons and once it is necessary, it should be populated.

The data is DB and is very expensive, so I want if I have concurrent calls, then refresh it only once (this is, if I get calls to refresh 500, then I just once wants to restart the refresh I)

  public static Pejdata example {get (m_Instance == null) {lock (instanceLock) {If (m_Instance == nULL) {m_Instance = New PageData ( ); }}} Return m_Instance; }} Public Zero ReSync () {lock (instanceLock) {/ * To re-install the installation to re-create the setting * / m_Instance = null; Pageadata pData = example; }}   

thanks

This is a bit wrong , Your

if (m_Instance == faucet)

really should be inside the lock.

Sorry, did not pay attention to it.

Nothing has been made that will allow other clients to quietly leave the call. If you are already refreshing the timeout will create an exception that I think. Perhaps maintain a stale date time that you can check to avoid refreshing those who make queued calls.

Comments