I want to write some statistics to a text file every time a person loads a page. But every time at some time I get an error like "I can not open the file already in use." I cannot repeat this error 100%, it is very unstable. My code
Public Sub WriteStats(ByVal ad_id As Integer)
Dim ad_date As String = Now.Year & Now.Month
Dim FILENAME As String = Server.MapPath("text/BoxedAds.txt")
Dim objStreamWriter As StreamWriter
objStreamWriter = File.AppendText(FILENAME)
objStreamWriter.WriteLine(ad_id & ";" & ad_date)
objStreamWriter.Close()
End Sub
My question is, how can I lock and unlock a file so that I stop receiving errors with an error?
thanks
source
share