Click here to Skip to main content
16,021,125 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
SearchLink = new Thread(new ThreadStart(() =>getData("http://" + TextBox1.Text.Trim())));
            SearchLink.Start();
            foreach (string value in myatt)
            {
                Label1.Text += value;
            }


Code Under Method Name getData is :

C#
private void getData(string Url)
    {
        HyperLink1.Text = string.Empty;
        HtmlWeb web = new HtmlWeb();
        HtmlDocument myNode = web.Load(Url);

        
        
        foreach (HtmlNode link in myNode.DocumentNode.SelectNodes("//a[@href]"))
        {
            HtmlAttribute att = link.Attributes["href"];
            myatt.Add(att.Value);
        }
        
    }


i tried with debug but not getting that what is happening in my code ....
and i am getting error

Collection was modified; enumeration operation may not execute.



help me to find out where i am wrong..

many thanks..
Posted

1 solution

Hi,

Try this:
C#
SearchLink = new Thread(new ThreadStart(() =>getData("http://" + TextBox1.Text.Trim())));
            SearchLink.Start();
            SearchLink.Join();
            foreach (string value in myatt)
            {
                Label1.Text += value;
            }

C#
private void getData(string Url) // you don't need to make any change on your getData method
    {
        HyperLink1.Text = string.Empty;
        HtmlWeb web = new HtmlWeb();
        HtmlDocument myNode = web.Load(Url);
 
        
        
        foreach (HtmlNode link in myNode.DocumentNode.SelectNodes("//a[@href]"))
        {
            HtmlAttribute att = link.Attributes["href"];
            myatt.Add(att.Value);
        }
        
    }

Hope this helps.
 
Share this answer
 
v4
Comments
Anjanee Kumar Singh 2-Aug-13 5:04am    
Invoke((MethodInvoker) these line giving me error in asp.net page
Thomas Daniels 2-Aug-13 5:09am    
I'm sorry, I thought you was using Windows Forms. I updated my answer
Anjanee Kumar Singh 2-Aug-13 5:10am    
actually i m sorry i didn't mention
Thomas Daniels 2-Aug-13 5:13am    
No problem.
Anjanee Kumar Singh 2-Aug-13 5:12am    
sir what this join() will do...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900