Non-reentrant timers

后端 未结 5 477
别那么骄傲
别那么骄傲 2020-12-11 04:30

I have a function that I want to invoke every x seconds, but I want it to be thread-safe.

Can I set up this behavior when I am creating the timer? (I don\'t

5条回答
  •  一向
    一向 (楼主)
    2020-12-11 05:07

    I know I can implement locks inside my callback function, but I think it will be more elegant if it will be in the timer level

    If locking is necessary then how could a timer arrange that? You're looking for a magical freebie.

    Re Edit1:

    Your choices are System.Timers.Timer and System.Threading.Timer, both need precautions against re-entrance. See this page and look for the Dealing with Timer Event Reentrance section.

提交回复
热议问题