How to synchronize the access to a List used in ASP.NET?

后端 未结 4 529
北荒
北荒 2021-01-01 03:58

I have some problems on a site with the concurrent access to a list. This list keeps a cart of items, and multiple deletes are crashing the site. Which is the best m

4条回答
  •  灰色年华
    2021-01-01 04:23

    So is this in-memory list shared between requests? That sounds like a potential cause of problems even when you've got locking. Mutable shared collections should generally be avoided, IME.

    Note that if you do decide to synchronize, you'll need to do things like locking the list for the whole course of iterating over it and other compound operations. Just locking on each specific access isn't good enough.

提交回复
热议问题