View Single Post
  #1 (permalink)  
Old August 22nd, 2004, 02:56 AM
mehdi62b mehdi62b is offline
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default Multiple simultaneous asynchronous requests

Hi everyone,
I was reading an article in Imar's Homepage
http://imar.spaanjaars.com/ViewConte...=4&CATEGORY=11
about
Howto Create a Hit Counter Using a Text File in ASP.NET
now I have a question in Session_Start event we make everytime a file
and set it to new counters ,here I cant get if there are many simultaneous asynchronous requests what will happen
Code:
protected void Session_Start(Object sender, EventArgs e)
{

  totalNumberOfUsers += 1;
  currentNumberOfUsers += 1;

  string counterFile = Server.MapPath("/Counter.txt"); 
  if (File.Exists(counterFile))
  {
    File.Delete(counterFile);
  }
  StreamWriter sw = File.CreateText(counterFile);
  sw.WriteLine ("Total\t" + totalNumberOfUsers);
  sw.Close(); 

}
I dont know maybe Session_Start could guarantee this and dont let simultaneous requests at the same time(while the file is ready for writing)
can anybody guide me in this regard.
(I know also there is such situations in Database but the DBMS can handle it correctly but here I dont know how it could be handled).
Thanks.

--------------------------------------------
Mehdi.:)
__________________
_____________
<font color=\"teal\"><font size=\"1\"><b>Mehdi.
software student.</b></font id=\"size1\"></font id=\"teal\">