Is there a synchronization class that guarantee FIFO order in C#?

前端 未结 7 1606
无人共我
无人共我 2020-11-28 11:01

What is it and how to use?

I need that as I have a timer that inserts into DB every second, and I have a shared resource between timer handler and the main thread. I

7条回答
  •  旧时难觅i
    2020-11-28 11:30

    There is no guaranteed order on any built-in synchronisation objects: http://msdn.microsoft.com/en-us/library/ms684266(VS.85).aspx

    If you want a guaranteed order you'll have to try and build something yourself, note though that it's not as easy as it might sound, especially when multiple threads reach the synchronisation point at (close to) the same time. To some extent the order they will be released will always be 'random' since you cannot predict in which order the point is reached, so does it really matter?

提交回复
热议问题