/// <summary> /// Validates pooled object state. An invalid object will not get into the pool and it will /// not be returned to consumers. /// </summary> /// <param name="validationContext">The validation context.</param> /// <returns>True if current pooled object is valid, false otherwise.</returns> internal bool ValidateObject(PooledObjectValidationContext validationContext) { if (OnValidateObject != null) { try { return(OnValidateObject.GetInvocationList() .Cast <Func <PooledObjectValidationContext, bool> >() .All(validationDelegate => validationDelegate(validationContext))); } catch (Exception ex) { LogAction("[ObjectPool] An unexpected error occurred while validating an object", ex, MessageType.Error); return(false); } } return(true); }
/// <summary> /// Reset the object state. This method will be called by the pool manager just before the /// object is being returned to the pool. /// </summary> internal bool ResetState() { if (!ValidateObject(PooledObjectValidationContext.Inbound(this))) { return(false); } if (OnResetState != null) { try { OnResetState(this); this.PooledObjectInfo.LastOperateTime = EvictionSettings.GetCurrentTime();//DateTime.Now; } catch (Exception ex) { LogAction("[ObjectPool] An unexpected error occurred while resetting state", ex, MessageType.Error); return(false); } } return(true); }