我有单独的对象’服务’和两个初始化和释放它的方法:
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; } } } }
对于带注释resharper的行(我使用版本5.1)显示一个提到的警告…
问题1:为什么?
问题2:为什么它不在’EnsureServiceIsOpened’方法中显示“类似”消息?
谢谢.