I have one service in C# which fetch records from oracle DB and insert into MySql DB, after a successful insert of all records in MySql DB one of the column of my Oracle DB gets an updated i.e these many records has got inserted.
Since being a service it’s getting called after every 5 sec.
My problem is that how should i handle the deadlock situation in this case. Like my service fetches around 20,000 records from oracle DB and trying to insert in to MySql DB that takes around 7-8 seconds, mean while my service will get called, and since all records of previous session are not getting inserted there won’t be update in Oracle DB and next time it will again fetch the whole records, that i don’t want.
If possible provide some same code as well. This is pure Window base service not WCF.
If you need “coordination” only in this service then use AutoResetEvent class.
working.
Using of WaitOne(TimeSpan timeout) with small timeout allow to finish timer “call” quickly if previous one is not finished yet.. So you still get ability to call you methods each 5 s.
Sure checking about AutoResetEvent disposing will be needed before call its methods and maybe some additional checks…