-1
In the method RealizarPesquisa, when executing the line _WebBrowser.Navigate(), the event is triggered DocumentCompleted(), but this event it takes a while to be executed, so the method RealizarPesquisa continues its process and when I go to get the Document, it is coming null because the eventoDocumentCompleted has not yet been completed, I tried to use the AutoResetEvent, but I did not succeed, someone has some suggestion?
    public class GoogleSearch
{
    private WebBrowser _WebBrowser;
    private string _TituloPesquisa;
    private string _LinkPesquisa;
    private List<GoogleResultado> _GoogleResultadoList;
    static AutoResetEvent aguardarDocumentCompleted = new AutoResetEvent(false);
    public GoogleSearch()
    {
        ConfigurarWebBrowser();
        _GoogleResultadoList = new List<GoogleResultado>();
    }
    public string GetResultJson 
    { 
        get
        {
            return _GoogleResultadoList.ToJsonSerialization<GoogleResultado>();
        }
    }
    public IEnumerable<GoogleResultado> GetListResults
    {
        get
        {
            return _GoogleResultadoList.ToList();
        }
    }
    public void Pesquisar(string textoConsulta)
    {
        RealizarPesquisa(textoConsulta);             
    }
    private void _WebBrowserDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        aguardarDocumentCompleted.Set();
        if (_WebBrowser.Document != null)
        {
            // Resultado em Html - Obter as Divs onde ficam o resultado da pesquisa do google.
            HtmlElementCollection divs = _WebBrowser.Document.GetElementsByTagName("div");
            // Obter dados da pesquisa.
            _TituloPesquisa = _WebBrowser.Document.Title;
            _LinkPesquisa = _WebBrowser.Document.Url.ToString();
            GoogleResultado resultado;
            foreach (HtmlElement x in divs)
            {
                // Div onde fica o resultado das pesquisas do google.
                if (x.GetAttribute("className") == "g")
                {
                    HtmlElement link = x.GetElementsByTagName("a")[0];
                    resultado = new GoogleResultado();
                    resultado.Titulo = link.InnerText;
                    resultado.Url = link.GetAttribute("href");
                    _GoogleResultadoList.Add(resultado);
                }
            }
        }           
    }
    private void ConfigurarWebBrowser()
    {
        _WebBrowser = new WebBrowser();
        _WebBrowser.DocumentCompleted += _WebBrowserDocumentCompleted;
        _WebBrowser.Url = new Uri("http://www.google.com", UriKind.Absolute);
    }
    private void RealizarPesquisa(string textoConsulta)
    {
        _WebBrowser.Navigate("https://www.google.com/search?num=100&q=" + textoConsulta);
        aguardarDocumentCompleted.WaitOne();
        var document = _WebBrowser.Document;
    }
}
Why not put inside the completed event?
– Aline
I cannot do this because I need the document in the return of the Realizarpesquisa method.
– Nicola Bogar