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

前端 未结 7 1567
无人共我
无人共我 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条回答
  •  攒了一身酷
    2020-11-28 11:30

    You should re-design your system to not rely on the execution order of the threads. For example, rather than have your threads make a DB call that might take more than one second, have your threads place the command they would execute into a data structure like a queue (or a heap if there is something that says "this one should be before another one"). Then, in spare time, drain the queue and do your db inserts one at a time in the proper order.

提交回复
热议问题