I am creating a Windows Server which will install itself on dobleclick. But i am writing the core code. The problem i am facing is
The windows Server will fetch 10 records from database and upload using a WCF Service.
Now after the completing of these 10 records, the service will again look into database and take again 10 records.
But i am also using Timer so that this process will continue every after 5 minutes. Now if at certain time, this upload using WCF took more than 5 Minutes, i have to stop the new execution and wait until it is complete.
How can i perform.
This is an ideal scenario for locking. In the below example the callback will trigger every 5 minutes. If the service is still processing a previous batch when the next callback triggers it will simply discard it and try again in 5 minutes time. You can change this to have the callbacks queue up if you prefer, however, you would need to be wary of thread pool starvation if you queue too many.
You could even reduce your interval to say 1 minute to avoid any long delays in the scenario where a batch runs over.