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

Untitled

By: a guest on Jun 2nd, 2012  |  syntax: None  |  size: 1.46 KB  |  hits: 11  |  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. Global variable in ASP.NET
  2. private static bool _isProcessingNewIllustrationRequest;
  3.  
  4.     public static bool IsProcessingNewIllustrationRequest
  5.     {
  6.         get { return _isProcessingNewIllustrationRequest; }
  7.         set { _isProcessingNewIllustrationRequest = value; }
  8.     }
  9.        
  10. public ActionResult CreateNewApplication()
  11.     {
  12.         if (!Global.IsProcessingNewIllustrationRequest)
  13.         {
  14.             Global.IsProcessingNewIllustrationRequest = true;
  15.  
  16.             // DO WORK... RUN CODE
  17.             Global.IsProcessingNewIllustrationRequest = false;
  18.             return View("Index", model);
  19.         }
  20.         else
  21.         {
  22.             // DISPLAY A MESSAGE THAT ANOTHER REQUEST IS IN PROCESS
  23.         }
  24.     }
  25.        
  26. private Object thisLock = new Object();    
  27. public ActionResult CreateApplication()
  28.         {
  29.             ILog log = LogManager.GetLogger(typeof(Global));
  30.             string aa = this.ControllerContext.HttpContext.Session.SessionID;
  31.             log.Info("MY THREAD: " + aa);
  32.  
  33.             lock (thisLock)
  34.             {
  35.                 Thread.Sleep(8000);
  36.  
  37.                 DO SOME STUFF
  38.  
  39.             }
  40.         }
  41.        
  42. public static Mutex _myMutex = new Mutex(false, @"GlobalSomeUniqueName");
  43.  
  44. public ActionResult CreateNewApplication()
  45. {
  46.     if (_myMutex.WaitOne(TimeSpan.Zero))
  47.     {
  48.         // DO WORK... RUN CODE
  49.         _myMutex.ReleaseMutex();
  50.         return View("Index", model);
  51.     }
  52.     else
  53.     {
  54.         // DISPLAY A MESSAGE THAT ANOTHER REQUEST IS IN PROCESS
  55.     }
  56. }