Boolean Variable in C# .NET Not Being Set

I developed a Windows service a couple of years ago that rids dormant user objects from Active Directory. It was a fairly simple service that did what it needed to do and took into consideration the quirks of Microsoft's Active Directory Domain structure such as when users authenticate, they do so against a single domain controller with that timestamp being stored instantly on just that DC. Eventually this timestamp gets replicated to other domain controllers but that can take up to a couple of weeks.

I recently had to add additional functionality to the service so that it would clean up AD accounts referenced from an Oracle database too. Rather than having to install the Oracle SQL*Net client on the Windows server where the service runs (which could be one of the DCs), I decided to call a web service running on a web server when performing the cleanup against the Oracle database. Within the logic executed by the Windows service, I generally place a boolean variable so that the service knows if it is already running or not each time the timer fires. If it is already running, the logic is skipped until the next time it is set to fire. Adding a call to a web service caused the logic to run once but after that it failed to run again because it thought the timer from the last firing was still being processed.

Follow up:

My development environment was Microsoft Visual Studio 2005 with .NET 2.0 running on a Windows XP Professional machine. Of course it is entirely possible that Microsoft may have fixed this problem by now since there have been several releases of VS, .NET, and OS since then.

Within the logic used to remove records from the Oracle database tied to AD, it makes one call to two different web service methods. The first is to obtain a list of information from the Oracle database. The second is called only if records retrieved via the first method need to be deleted. All works fine up to the point where the second method is called. In the code, the boolean switch is set to FALSE immediately following the return from the call to the second method. To verify this code is being executed, a logging statement was placed just after the return from the second method. A log entry was created however the next time the timer fired within the Windows service, the boolean switch was still set to TRUE - indicating the process was still running. The switch stayed TRUE until the service was stopped then restarted.

I decided to try placing a sleep or delay of 5 seconds in the logic just after returning from the call to the second web service and before the boolen switch is set to FALSE. This trick worked. During the run of the Windows service, the boolean switch was set to FALSE so the next time the timer fired, the process to check Oracle for dormant records was run again.

The only real difference between the first web method and the second was that the second method executed Oracle delete from table and commit statements. The first web method only executed an Oracle select statement. When there were no records to remove and before this fix, the boolean switch was being set to FALSE correctly. When there were records to remove, the switch remained set to TRUE even though the bVariableName = false statement was being executed.