>public void FindActiveWebService() >{ > // Moved outside the lock > if (IsFindingActiveWebService) > return; > > lock (FindWebServiceSync) > { > IsFindingActiveWebService = true; > try > { > // Lots of crappy code and nested code in here with loops and such. > // Planning to refactor all this junk. > } > finally > { > IsFindingActiveWebService = false; > } > } >} >Let's supposed IsFindingActiveWebService is false. One thread calls FindActiveWebService() and makes it past the return. At the same time, another thread calls this same code. It also makes it past this check. The first thread has locked FindWebServiceSync, so the other thread is currently blocked. It appears like the only reason for IsFinidingActiveWebService (if it's not used anywhere else) is to keep threads from piling up here under heavy loads (although you could do this with just the FindWebServicesSync by checking if it's locked).