为什么表达式总是适用于'双重检查锁定'?

Bud*_*dda 6 c# resharper singleton

我有单独的对象'服务'和两个初始化和释放它的方法:

public class BaseService
{
    protected static readonly object StaticLockObject = new object();
}

public abstract class WebServiceBase<TService> : BaseService
    where TService : System.Web.Services.Protocols.SoapHttpClientProtocol, new()
{
    protected static void EnsureServiceIsOpened()
    {
        if (Service == null)
        {
            lock (StaticLockObject)
            {
                if (Service == null)
                {
                    Service = new TService();
                }
            }
        }
    }

    protected static void EnsureServiceIsClosed()
    {
        if (Service != null)
        {
            lock (StaticLockObject)
            {
                if (Service != null) // Why expression is always true
                {
                    Service.Dispose();
                    Service = null;
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

对于带注释resharper的行(我使用版本5.1)显示一个提到的警告...

问题1:为什么?

问题2:为什么它不在'EnsureServiceIsOpened'方法中显示"类似"消息?

谢谢.

Evg*_*kov 2

这是 ReSharper 5.X 代码分析引擎中的错误。在 ReSharper 6.0 中已修复。

顺便说一句,ReSharper 6 带来了更多双锁模式分析的东西:)