Hi
I have some code from a friend and I don't understand why they have used the application lock feature! I understand this produces a random quote, but can some one explain to me what happens with the application lock and why it's in use (see lines 19 - 21)?
Thank you
I have some code from a friend and I don't understand why they have used the application lock feature! I understand this produces a random quote, but can some one explain to me what happens with the application lock and why it's in use (see lines 19 - 21)?
Code:
public class QuoteClass : UserControl { public HtmlGenericControl divQuote; void Page_Load(Object source, EventArgs e) { divQuote.InnerHtml = RandomQuote(); } public string RandomQuote() { int intRandomNum; string strQuote = ""; Random rndQuote = new System.Random(GetHashCode()); intRandomNum = rndQuote.Next(1,4); switch(intRandomNum) { case 1: strQuote = "An apple a day keeps the doctor away. -- Anonymous"; Application.Lock(); Application["Quote1"] = Convert.ToInt32(Application["Quote1"]) + 1; Application.UnLock(); break; case 2: strQuote = "Thought product and food product are to me nothing compared to the producing of them. -- Robert Frost"; Application.Lock(); Application["Quote2"] = Convert.ToInt32(Application["Quote2"]) + 1; Application.UnLock(); break; case 3: strQuote = "Eat to live, and not live to eat. -- Benjamin Franklin"; Application.Lock(); Application["Quote3"] = Convert.ToInt32(Application["Quote3"]) + 1; Application.UnLock(); break; } return strQuote; } }
Comment