Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9153383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:15:48+00:00 2026-06-17T12:15:48+00:00

I’m trying to populate a grid with some data extracted from linkedin, im just

  • 0

I’m trying to populate a grid with some data extracted from linkedin, im just trying to get it working for my own learning curve, BUT if I remove the line

MessageBox.Show("asdfasdfasdf")

the list “messages” only has 1 item, if I include the line above it does whats expected and I get 15 messages

Can someone explain?

public void extract_messages_received(object sender, RoutedEventArgs e)
{
    triggered = false;
    System.Windows.Forms.WebBrowser browser = new System.Windows.Forms.WebBrowser();
    browser.Navigate(new Uri(@"http://www.linkedin.com/inbox/messages/received"));
    browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
}

private void LoadMessages(string url)
{
    txtOutput.Text = @"http://www.linkedin.com" + url.Substring(6, url.Length - 6);
    if (!urls.Contains(url))
    {
        urls.Add(url);
        WebBrowser browser = new WebBrowser();
        browser.Navigate(new Uri(txtOutput.Text);

        loaded_message = false;
        browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(ReadMessages);
    }
}

private void ReadMessages(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    if (loaded_message == false)
    {        
        string url = ((WebBrowser)sender).Url.ToString();
        int loc1 = url.IndexOf("itemID") + 7;
        int loc2 = url.IndexOf("&", loc1);
        IEnumerable<string> name = null;
        IEnumerable<string> odate = null;
        IEnumerable<string> photo = null;
        IEnumerable<string> subject = null;
        IEnumerable<string> headline = null;
        string body = "";
        string id = url.Substring(loc1, loc2 - loc1);
        //System.Windows.MessageBox.Show("READ");
        foreach (HtmlElement element in ((WebBrowser)sender).Document.GetElementsByTagName("div"))
        {
            if (element.GetAttribute("classname").Equals("inbox-item-body"))
            {
                body = element.InnerText;
            }
            if (element.GetAttribute("classname").Equals("inbox-item-header"))
            {
                var doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(element.InnerHtml);
                name = from foo in doc.DocumentNode.SelectNodes("//a[@class='fn']") select foo.InnerText;
                odate = from foo in doc.DocumentNode.SelectNodes("//p[@class='date']") select foo.InnerText;
                photo = from foo in doc.DocumentNode.SelectNodes("//img[@class='photo']") select foo.Attributes["src"].Value;
                subject = from foo in doc.DocumentNode.SelectNodes("//h3") select foo.InnerText;
                headline = from foo in doc.DocumentNode.SelectNodes("//span[@class='headline']") select foo.InnerText;
            }
        }

        // ****
        MessageBox.Show("asdfasdfasdf");
        // ****

        messages.Add(new Messages()
        {
            ID = id,
            Subject = subject.First().ToString(),
            Headline = headline.First().ToString(),
            Sender = name.First().ToString(),
            Photo = photo.First().ToString(),
            SendDate = odate.First().ToString(),
            Body = body
        });

           // dataMessages.ItemsSource = messages;
    }
    loaded_message = true;
}

void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    if (!triggered)
    {
        triggered = true;
        System.Windows.Forms.WebBrowser web = sender as System.Windows.Forms.WebBrowser;
        foreach (HtmlElement element in web.Document.GetElementsByTagName("ol"))
        {
            if (element.GetAttribute("classname").Contains("inbox-list "))
            {
                WebBrowser browser = new WebBrowser();
                browser.Navigate("about:blank");
                browser.Document.Write(element.InnerHtml);
                HtmlElementCollection hrefTags = null;
                hrefTags = browser.Document.GetElementsByTagName("a");
                foreach (HtmlElement a in hrefTags)
                {
                    if (a.OuterHtml.Contains("displayMBox"))
                    {
                        LoadMessages(a.GetAttribute("href"));
                    }
                }
            }
        }
    }       
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:15:49+00:00Added an answer on June 17, 2026 at 12:15 pm

    This is a timing issue.

    When you have the message box in there, loaded_message doesn’t get set to true until after you close the message box, so the other events are processing up until the message box as well, with none of them settings loaded_message to true until you close the first message box.

    If you close the messagebox quickly enough, you will probably see some number beteween 1 and 15.

    Let’s take a more simplistic example:

        private void Form1_Load(object sender, EventArgs e)
        {
    
            for (int i = 0; i < 5; i++)
            {
                WebBrowser wb = new WebBrowser();
                wb.DocumentCompleted += wb_DocumentCompleted;
                wb.Navigate("http://www.stackoverflow.com");
            }
        }
    
        bool shown = false;
        void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (!shown)
            {
                Console.WriteLine(shown);
                MessageBox.Show(shown.ToString());
                shown = true;
            }
        }
    

    Now, if you watch the console, you will see a few false show up before the first message box is shown. When I close the message box, I then see 4 more messageboxes because those were already queued up and waiting to show before shown got set to true. If I comment out the messagebox, then I get only one message box shown and one false in the console.

    Now, the question becomes, why did you add and need to check the loaded_message boolean variable.

    My guess is that you only want to load each message only once. If that is the case, keep track of each URL in a dictionary and maintain a bool for each URL:

        Dictionary<string, bool> loadedUrls = new Dictionary<string, bool>();
        private void Form1_Load(object sender, EventArgs e)
        {
    
            for (int i = 0; i < 5; i++)
            {
                WebBrowser wb = new WebBrowser();
                wb.DocumentCompleted += wb_DocumentCompleted;
                string url = "http://stackoverflow.com/" + i;
    
                loadedUrls.Add(url, false);
                wb.Navigate(url);
            }
        }
    
        bool shown = false;
        void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
    
            if (loadedUrls.ContainsKey(e.Url.OriginalString) && loadedUrls[e.Url.OriginalString] == false)
            {
                loadedUrls[e.Url.OriginalString] = true;
                Console.WriteLine(shown);
                shown = true;
            }
        }
    

    I left shown in there to demonstrate that this new approach now works for each pass in the document completed event. Your output window should have a false followed by 4 true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have just tried to save a simple *.rtf file with some websites and
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am using jsonparser to parse data and images obtained from json response. When
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.