예제 #1
0
        private bool disposedValue = false; // 要检测冗余调用

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: 释放托管状态(托管对象)。
                    if (service.State == CommunicationState.Opened)
                    {
                        service.Close();
                    }
                }

                // TODO: 释放未托管的资源(未托管的对象)并在以下内容中替代终结器。
                // TODO: 将大型字段设置为 null。

                disposedValue = true;
            }
        }
예제 #2
0
        public static async Task Execute(ServiceAction <Task> action)
        {
            using (var service = new Server.NetCacheServiceClient())
                try
                {
                    service.Open();
                    //service.ClientCredentials.UserName.UserName = "******";
                    //service.ClientCredentials.UserName.Password = "******";

                    await action(service);
                }
                catch (Exception exception)
                {
                    //Logging.LogHelper.Logger.LogException(exception);
                }
            finally
            {
                if (service.State == CommunicationState.Opened)
                {
                    service.Close();
                }
            }
        }