
Untitled
By: a guest on
Jun 2nd, 2012 | syntax:
None | size: 1.46 KB | hits: 11 | expires: Never
Global variable in ASP.NET
private static bool _isProcessingNewIllustrationRequest;
public static bool IsProcessingNewIllustrationRequest
{
get { return _isProcessingNewIllustrationRequest; }
set { _isProcessingNewIllustrationRequest = value; }
}
public ActionResult CreateNewApplication()
{
if (!Global.IsProcessingNewIllustrationRequest)
{
Global.IsProcessingNewIllustrationRequest = true;
// DO WORK... RUN CODE
Global.IsProcessingNewIllustrationRequest = false;
return View("Index", model);
}
else
{
// DISPLAY A MESSAGE THAT ANOTHER REQUEST IS IN PROCESS
}
}
private Object thisLock = new Object();
public ActionResult CreateApplication()
{
ILog log = LogManager.GetLogger(typeof(Global));
string aa = this.ControllerContext.HttpContext.Session.SessionID;
log.Info("MY THREAD: " + aa);
lock (thisLock)
{
Thread.Sleep(8000);
DO SOME STUFF
}
}
public static Mutex _myMutex = new Mutex(false, @"GlobalSomeUniqueName");
public ActionResult CreateNewApplication()
{
if (_myMutex.WaitOne(TimeSpan.Zero))
{
// DO WORK... RUN CODE
_myMutex.ReleaseMutex();
return View("Index", model);
}
else
{
// DISPLAY A MESSAGE THAT ANOTHER REQUEST IS IN PROCESS
}
}