How do I know if this C# method is thread safe?

后端 未结 11 1540
不知归路
不知归路 2020-12-07 13:19

I\'m working on creating a call back function for an ASP.NET cache item removal event.

The documentation says I should call a method on an object or calls I know wil

11条回答
  •  清歌不尽
    2020-12-07 13:55

    any access to an obect that can be used simultaneously by two threads is not threadsafe.

    your example in Part 2 is clearly safe, as it uses only values passed in as arguments, but if you used an object scoped variable you might have to surround the access with appropriate lock statements

提交回复
热议问题