Don't like ads? PRO users don't see any ads ;-)
Guest

WebExtentions

By: andrew4582 on Dec 14th, 2011  |  syntax: C#  |  size: 2.27 KB  |  hits: 90  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     /// <summary>
  2.     /// V1  Wednesday December 14,2011 8:42 PM
  3.     /// </summary>
  4.     public static partial class WebExtentions {
  5.  
  6.         public static void LockWrite(this HttpApplicationStateBase application,string key,Func<string,object,object> valueFunc) {
  7.            
  8.             if(application == null)
  9.                 throw new ArgumentNullException("application");
  10.             if(key == null)
  11.                 throw new ArgumentNullException("key");
  12.             if(valueFunc == null)
  13.                 throw new ArgumentNullException("valueFunc");
  14.  
  15.             try {
  16.                 application.Lock();
  17.                 object existing = application[key];
  18.                 application[key] = valueFunc(key,existing);
  19.             }
  20.             finally {
  21.                 application.UnLock();
  22.             }
  23.         }
  24.         public static void LockWrite(this HttpApplicationStateBase application,string key,object value) {
  25.  
  26.             if(application == null)
  27.                 throw new ArgumentNullException("application");
  28.             if(key == null)
  29.                 throw new ArgumentNullException("key");
  30.  
  31.             try {
  32.                 application.Lock();
  33.                 application[key] = value;
  34.             }
  35.             finally {
  36.                 application.UnLock();
  37.             }
  38.         }
  39.         public static void LockWrite(this HttpSessionStateBase state,string key,Func<string,object,object> valueFunc) {
  40.             if(state == null)
  41.                 throw new ArgumentNullException("state");
  42.             if(key == null)
  43.                 throw new ArgumentNullException("key");
  44.             if(valueFunc == null)
  45.                 throw new ArgumentNullException("valueFunc");
  46.  
  47.             lock(state) {
  48.                 object existing = state[key];
  49.                 state[key] = valueFunc(key,existing);
  50.             }
  51.         }
  52.         public static void LockWrite(this HttpSessionStateBase state,string key,object value) {
  53.  
  54.             if(state == null)
  55.                 throw new ArgumentNullException("application");
  56.             if(key == null)
  57.                 throw new ArgumentNullException("key");
  58.  
  59.             lock(state) {
  60.                 object existing = state[key];
  61.                 state[key] = value;
  62.             }
  63.         }
  64.     }