Is .NET DateTime thread safe

后端 未结 2 1241
南方客
南方客 2020-12-10 13:06

Is .NET DateTime thread safe? I\'m not worried if the read operation returns incorrect value, my only concern is: will DateTime object get corrupted if not synchron

2条回答
  •  佛祖请我去吃肉
    2020-12-10 13:53

    DateTime is an immutable value type (struct). You cannot change an instance once created.

    It will not get corrupted and is thread safe.

    If you are changing a DateTime variable from multiple threads (either writing or reading/writing), you need to synchronize - as this operation is not thread safe.

提交回复
热议问题