HttpApplicationState - Why does Race condition exist if it is thread safe?

后端 未结 2 1426
死守一世寂寞
死守一世寂寞 2021-01-15 02:51

I just read an article that describes how HttpApplicationState has AcquireRead() / AcquireWrite() functions to manage concurrent access. It continues to explain

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-15 03:31

    HttpApplicationState - where the globally access variables those are visible to all the

    users who are using the application. So in order to avoid the race condition while changing

    the value of the variables. We need some precautionary, thats why we are using

    Application.Lock() and after the job done releasing the same variable to others in the

    queue using Application.Unlock()

    Application.Lock()
    Application("VisitorCount") = Convert.ToInt32(Application("VisitorCount")) + 1
    Application.UnLock()
    

提交回复
热议问题