It seems that Resharper is making a mistake in this analysis. Since Service not a local variable, it cannot know that this expression will always be true.
The reason why the error does not appear for the first version is probable, because the idiom with double check for blocking is so common, and this is its usual form. They probably tried this case and removed the erroneous warning.
The technique displayed in EnsureServiceIsClosed is not general because it contains a race condition. Another thread may use the object designated by Service , while or after its removal. This would not be possible if the code that uses the service lock on StaticLockObject , but if it accepts the lock, then there is no reason to do all this double-checked rigamarole locking around creating and deleting an object. Therefore, it is obvious that this code is erroneous.
source share