Making a web page only execute one at a time

Discussion in 'ASP.NET / ASP.NET Core' started by strazz, Jun 12, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I have an .aspx web form in my website and I have it set up to be hit once per hour. I have a special requirement, however. There are tons of things being done inside the 'Page_Load' event and I only want that code executing one at a time. In other words, if the web form was hit twice at about the same time, I dont want the Page_Load executing twice at the same time. I want the first 'Page_Load' to be completely done before the second 'Page_Load' even starts. How do I set this up? The rest of the web app needs to be running at full speed at this time of course, I just am concerned with the Page_Load on this particular web form. This probably has something to do with locking and threads but I can't find out how to do it.
     
  2. You'll have to create some sort of lock.

    The first thing you do in a page is test this lock, make sure "lock != on". If "lock==on" exit the page.

    Nextwrite to a file or database that will say something like "lock=on" and continue your processing.

    At the end of the page make sure you take the lock off.


    note: there may be problems with the lock being set to 'on' and never turned off. If you can store another variable like DateTime, then you can check that to see if the lock is new or old (and rewrite the lock if its old).




    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  3. I wanted to post what I finally went with, thank you for responding :- ):



    Old Code:



    //1. check if it hasn?t been updated in an hour

    //2. run code to update (takes about 20 seconds)

    //3. update database to current updated time



    New Code:



    Mutex m = new Mutex(false, 'update');

    //searched the entire application for a mutex named ?update?. False means do not try to gain access yet.

    try

    {

    m.WaitOne();

    //1. check it it hasn?t been updated in an hour

    //2. Run code to update (takes 20 seconds)

    //3. update database to current updated time

    }



    catch(Exception exc)

    {

    Util.sendErrorEmail(exc.ToString());

    }

    finally

    {

    m.ReleaseMutex();

    }
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page