title: Synchronization problems with Monitor class in WCF service
body: <p>I have a self-hosted WCF service and I'm having the following problem: 15 minutes after creating the instance of the service TryEnter calls in operation contract methods constantly return false, but the TryEnter calls in Main function, which also uses synchronization via Monitor class, return true.</p>
  
  <p>Here's the description of my app and the bug:
  I am developing a self-hosted WCF service in Visual Studio 2008 (C#) in Windows XP SP2.
  The ServiceHost instance of the host is created at the beginning of the Main function. The Main function runs a while (true) loop during which it performs periodic readings, writing, maintenance etc.
  There is a static collection of objects (which can be added or removed over time), which act as containers for worker threads. Some of these threads do periodic work requested by Main function, while others perform on-demand reading and writing to a remote device.  Synchronization locking is done on these objects using Monitor class (TryEnter and Exit methods). These objects are also accessed through the service contract methods (services) using the same functions. Synchronization is done between the Main function and the service methods. When the instance of the service is created, it runs with designed performance for exactly 15 minutes, after which every TryEnter(obj, timeout) call made from the service returns false after the specified timeout expires. This however doesn't affect the TryEnter calls made in the Main function i.e. they always return true.
  I have tried changing the settings for InstanceContextMode, ConcurrencyMode, coupled with service throttling attributes
  maxConcurrentCalls="1" ; maxConcurrentSessions="5"
  and every configuration gave the same effect. The service becomes responsive again when I restart the host app, but not when I forcibly close and reopen the host while the app is running (the service instance remains in the memory).
  It is not a case of service being unavailable, as in the call never making its way to the service instance. The method is called, its execution comes to the TryEnter call which precedes the critical section of the method and TryEnter just returns false after the timeout (15 seconds).
  I have checked and double checked the pairings of TryEnter and Exit – the methods always release the lock when the critical section ends.
  Other contract operations which don’t use locking or the objects in question work fine even after the 15 minute period has ended.</p>
  
  <p>Thank you all in advance.
  Happy holidays!</p>