private void EnsureHtmlParser() { if (!this._htmlParsed) { this._stopWorkerThread = false; this._parsingException = null; this._stateChangeResetEvent = new ManualResetEventSlim(); this._loadDocumentResetEvent = new ManualResetEventSlim(); this._onreadystatechangeEventHandler = new HTMLDocumentEvents2_onreadystatechangeEventHandler(this.ReadyStateChanged); ThreadPool.QueueUserWorkItem(new WaitCallback(this.LoadDocumentInMtaThread)); for (bool flag = true; flag; flag = !this._loadDocumentResetEvent.Wait(500)) { if (this._executionContext.CurrentPipelineStopping) { this._stopWorkerThread = true; this._loadDocumentResetEvent.Wait(); break; } } if (this._executionContext.CurrentPipelineStopping) { throw new PipelineStoppedException(); } if (this._parsingException != null) { throw this._parsingException; } this._htmlParsed = true; } if (_tagRegex == null) { _tagRegex = new Regex("<\\w+((\\s+[^\"'>/=\\s\\p{Cc}]+(\\s*=\\s*(?:\".*?\"|'.*?'|[^'\">\\s]+))?)+\\s*|\\s*)/?>", RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase); } if (_attribsRegex == null) { _attribsRegex = new Regex("(?<=\\s+)([^\"'>/=\\s\\p{Cc}]+(\\s*=\\s*(?:\".*?\"|'.*?'|[^'\">\\s]+))?)", RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase); } if (_attribNameValueRegex == null) { _attribNameValueRegex = new Regex("([^\"'>/=\\s\\p{Cc}]+)(?:\\s*=\\s*(?:\"(.*?)\"|'(.*?)'|([^'\">\\s]+)))?", RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase); } }
private void EnsureHtmlParser() { if (_htmlParsed == false) { // Initialization _stopWorkerThread = false; _parsingException = null; _stateChangeResetEvent = new ManualResetEventSlim(); _loadDocumentResetEvent = new ManualResetEventSlim(); _onreadystatechangeEventHandler = new HTMLDocumentEvents2_onreadystatechangeEventHandler(ReadyStateChanged); // The IHTMLDocument events cannot be handled in STA ApartmentState, so we use a worker thread to load the document ThreadPool.QueueUserWorkItem(new WaitCallback(LoadDocumentInMtaThread)); // Wait for the worker thread to finish loading the document. In the meantime, we check the Ctrl-C every 500ms bool wait = true; while (wait) { if (_executionContext.CurrentPipelineStopping) { // Signal and wait for the worker thread to exit, then break out the loop _stopWorkerThread = true; _loadDocumentResetEvent.Wait(); break; } wait = !_loadDocumentResetEvent.Wait(500); } // Ctrl-C is typed if (_executionContext.CurrentPipelineStopping) { throw new PipelineStoppedException(); } // If there is no Ctrl-C, throw if an exception happened during the parsing if (_parsingException != null) { throw _parsingException; } // Parsing was successful _htmlParsed = true; } if (_tagRegex == null) { _tagRegex = new Regex(@"<\w+((\s+[^""'>/=\s\p{Cc}]+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>", RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Compiled); } if (_attribsRegex == null) { _attribsRegex = new Regex(@"(?<=\s+)([^""'>/=\s\p{Cc}]+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)", RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Compiled); } if (_attribNameValueRegex == null) { _attribNameValueRegex = new Regex(@"([^""'>/=\s\p{Cc}]+)(?:\s*=\s*(?:""(.*?)""|'(.*?)'|([^'"">\s]+)))?", RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Compiled); } }