Hello Kannan,
I understand you want to run this program periodically, every "n" minutes (Example every 15 mniutes) to check status of process chains and if any failed process chain found in last "n" minutes, then send an email notification.
In this case since program will check status of process chain only within last "n" minutes, it will not have scenario where you have same process chain found with status "active" and "failed". It will also ensure no repetitive notifications to be sent for same failed process chain.
Please think about it and let me know if you need any help.
Thank you
Satish Waghmare