How to let Timer skip tick if the previous thread is still busy

后端 未结 8 1659
攒了一身酷
攒了一身酷 2020-12-01 11:28

I created a windows service, that is supposed to check a certain table in the db for new rows every 60 seconds. For every new row that was added, I need to do some heavy pro

8条回答
  •  伪装坚强ぢ
    2020-12-01 11:43

    another posibility would be something like this:

    void serviceTimer_Elapsed(object sender, ElapsedEventArgs e)
    {   
        if (System.Threading.Monitor.IsLocked(yourLockingObject))
           return;
        else
           lock (yourLockingObject)
           // your logic  
               ;
    }
    

提交回复
热议问题