Language: C#
Proper locking for static Properties in threaded/web Environments
private static object _SyncLock = new object(); public TableInfo<TEntity> TableInfo { get { if (_TableInfo == null) { lock (_SyncLock) { if (_TableInfo == null) _TableInfo = new TableInfo<TEntity>(); } } return _TableInfo; } set { _TableInfo = value; } } private static TableInfo<TEntity> _TableInfo = null;
Tags:
Description:
Note the double check for null outside (to avoid locking every time) and again inside of the lock to ensure the value hasn't already been changed.
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

