How to make objects Threadsafe on c#?

后端 未结 3 543
灰色年华
灰色年华 2021-01-07 06:30

I have a an application that requires threading in most cases. Most of the time I will encounter errors or wrong values because the object was updated prior to its execution

3条回答
  •  盖世英雄少女心
    2021-01-07 07:01

    Start here: Synchronizing Data for Multithreading

    Basically, you'll need to use a mutex. In .NET every object can act as a mutex, so you can use the lock keyword on any object to ensure mutual exclusions.

提交回复
热议问题