private void DestroyPTSContexts()
        {
            int i = 0;

            while (i < this._contextPool.Count)
            {
                PtsContext ptsContext = this._contextPool[i].Owner.Target as PtsContext;
                if (ptsContext != null)
                {
                    Invariant.Assert(this._contextPool[i].PtsHost.Context == ptsContext.Context, "PTS Context mismatch.");
                    this._contextPool[i].Owner = new WeakReference(null);
                    this._contextPool[i].InUse = false;
                    Invariant.Assert(!ptsContext.Disposed, "PtsContext has been already disposed.");
                    ptsContext.Dispose();
                }
                if (!this._contextPool[i].InUse)
                {
                    Invariant.Assert(this._contextPool[i].PtsHost.Context != IntPtr.Zero, "PTS Context handle is not valid.");
                    PTS.IgnoreError(PTS.DestroyDocContext(this._contextPool[i].PtsHost.Context));
                    Invariant.Assert(this._contextPool[i].InstalledObjects != IntPtr.Zero, "Installed Objects handle is not valid.");
                    PTS.IgnoreError(PTS.DestroyInstalledObjectsInfo(this._contextPool[i].InstalledObjects));
                    if (this._contextPool[i].TextPenaltyModule != null)
                    {
                        this._contextPool[i].TextPenaltyModule.Dispose();
                    }
                    this._contextPool.RemoveAt(i);
                }
                else
                {
                    i++;
                }
            }
        }
示例#2
0
        private void OnPtsContextReleased(bool cleanContextPool)
        {
            int index;


            lock (_lock)
            {
                if (_releaseQueue != null)
                {
                    foreach (PtsContext ptsContext in _releaseQueue)
                    {
                        for (index = 0; index < _contextPool.Count; index++)
                        {
                            if (_contextPool[index].PtsHost.Context == ptsContext.Context)
                            {
                                _contextPool[index].Owner = new WeakReference(null);
                                _contextPool[index].InUse = false;
                                break;
                            }
                        }
                        Invariant.Assert(index < _contextPool.Count, "PtsContext not found in the context pool.");


                        Invariant.Assert(!ptsContext.Disposed, "PtsContext has been already disposed.");
                        ptsContext.Dispose();
                    }
                    _releaseQueue = null;
                }
            }


            if (cleanContextPool && _contextPool.Count > 4)
            {
                index = 4;
                while (index < _contextPool.Count)
                {
                    if (!_contextPool[index].InUse)
                    {
                        Invariant.Assert(_contextPool[index].PtsHost.Context != IntPtr.Zero, "PTS Context handle is not valid.");
                        PTS.Validate(PTS.DestroyDocContext(_contextPool[index].PtsHost.Context));
                        Invariant.Assert(_contextPool[index].InstalledObjects != IntPtr.Zero, "Installed Objects handle is not valid.");
                        PTS.Validate(PTS.DestroyInstalledObjectsInfo(_contextPool[index].InstalledObjects));


                        if (_contextPool[index].TextPenaltyModule != null)
                        {
                            _contextPool[index].TextPenaltyModule.Dispose();
                        }
                        _contextPool.RemoveAt(index);
                        continue;
                    }
                    index++;
                }
            }
        }
        private void OnPtsContextReleased(bool cleanContextPool)
        {
            object @lock = this._lock;

            lock (@lock)
            {
                if (this._releaseQueue != null)
                {
                    foreach (PtsContext ptsContext in this._releaseQueue)
                    {
                        int i;
                        for (i = 0; i < this._contextPool.Count; i++)
                        {
                            if (this._contextPool[i].PtsHost.Context == ptsContext.Context)
                            {
                                this._contextPool[i].Owner = new WeakReference(null);
                                this._contextPool[i].InUse = false;
                                break;
                            }
                        }
                        Invariant.Assert(i < this._contextPool.Count, "PtsContext not found in the context pool.");
                        Invariant.Assert(!ptsContext.Disposed, "PtsContext has been already disposed.");
                        ptsContext.Dispose();
                    }
                    this._releaseQueue = null;
                }
            }
            if (cleanContextPool && this._contextPool.Count > 4)
            {
                int i = 4;
                while (i < this._contextPool.Count)
                {
                    if (!this._contextPool[i].InUse)
                    {
                        Invariant.Assert(this._contextPool[i].PtsHost.Context != IntPtr.Zero, "PTS Context handle is not valid.");
                        PTS.Validate(PTS.DestroyDocContext(this._contextPool[i].PtsHost.Context));
                        Invariant.Assert(this._contextPool[i].InstalledObjects != IntPtr.Zero, "Installed Objects handle is not valid.");
                        PTS.Validate(PTS.DestroyInstalledObjectsInfo(this._contextPool[i].InstalledObjects));
                        if (this._contextPool[i].TextPenaltyModule != null)
                        {
                            this._contextPool[i].TextPenaltyModule.Dispose();
                        }
                        this._contextPool.RemoveAt(i);
                    }
                    else
                    {
                        i++;
                    }
                }
            }
        }