I have tool which will send record .This tool can select multiple record at time but itsend event for each record.I want to get Max record by put dealy when i receive a RecordChangedEvent in my code as below:Its working good but for every event delayed occurred not sure why. RecordChangedEvent(void){        static bool lock=false;        bool updateNewRecord =false;        /*delaying for 20sec when frist event received so that max record can be received */        if(!lock)          {                lock=true;                std::this_thread::sleep_for(std::chrono::seconds(20));                updateNewRecord=true;          }        if(updateNewRecord)        {                      //ading after 20 sec dealy changed.list will have all the updated received record within 20 sec                                        AddedRecord(changed.list);                               lock=false;        }}
Getting max record by delaying in the received event
c++