/// <summary>
        /// Destroys object
        /// </summary>
        /// <param name="disposing">Flag, allowing destruction of
        /// managed objects contained in fields of class</param>
        private void Dispose(bool disposing)
        {
            if (_disposedFlag.Set())
            {
                _dispatcher.Invoke(() =>
                {
                    if (_dispatch != null)
                    {
                        ComHelpers.ReleaseComObject(ref _dispatch, !disposing);
                        _dispatch = null;
                    }

                    if (_activeScriptWrapper != null)
                    {
                        _activeScriptWrapper.Dispose();
                        _activeScriptWrapper = null;
                    }
                });

                if (disposing)
                {
                    if (_debuggingStarted && _debugDocuments != null)
                    {
                        foreach (UIntPtr debugDocumentKey in _debugDocuments.Keys)
                        {
                            var debugDocumentValue = _debugDocuments[debugDocumentKey];
                            debugDocumentValue.Close();
                        }

                        _debugDocuments.Clear();
                    }

                    if (_processDebugManagerWrapper != null)
                    {
                        _processDebugManagerWrapper.RemoveApplication(_debugApplicationCookie);
                        _debugApplicationWrapper.Close();
                    }

                    if (_hostItems != null)
                    {
                        _hostItems.Clear();
                    }

                    _lastException = null;
                }
            }
        }