예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityChangeMonitor{TEntity, TDbContext}" /> class.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="timeout">The timeout.</param>
        public EntityChangeMonitor(Expression <Func <TEntity, bool> > query, TimeSpan?timeout)
        {
            _context        = new TDbContext();
            _query          = query;
            _uniqueId       = Guid.NewGuid().ToString();
            _changeNotifier = new EntityChangeNotifier <TEntity, TDbContext>(_query, timeout);

            _changeNotifier.Error   += _changeNotifier_Error;
            _changeNotifier.Changed += _changeNotifier_Changed;

            InitializationComplete();
        }
예제 #2
0
        /// <summary>
        /// Releases all managed and unmanaged resources and any references to the <see cref="T:System.Runtime.Caching.ChangeMonitor" /> instance. This overload must be implemented by derived change-monitor classes.
        /// </summary>
        /// <param name="disposing">true to release managed and unmanaged resources and any references to a <see cref="T:System.Runtime.Caching.ChangeMonitor" /> instance; false to release only unmanaged resources. When false is passed, the <see cref="M:System.Runtime.Caching.ChangeMonitor.Dispose(System.Boolean)" /> method is called by a finalizer thread and any external managed references are likely no longer valid because they have already been garbage collected.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _query = null;

                if (_changeNotifier != null)
                {
                    _changeNotifier.Error   -= _changeNotifier_Error;
                    _changeNotifier.Changed -= _changeNotifier_Changed;

                    _changeNotifier.Dispose();
                    _changeNotifier = null;
                }
                _context.Dispose();
                _context = null;
            }
        }