Click here to Skip to main content
16,017,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Everyone....

I have a listview of htmltags(Links). I want to get response from every item of that listview .

when I start looping then my UI was not responding .
My code is..

C#
foreach (ListViewItem list in listView1.Items)
           {
               bool respond = checkrequest(list.Text);
               if (respond == true)
                   Do something......
               else others......
           }



public bool checkrequest(string url)
        {
            try
            {
                WebRequest webrequest =HttpWebRequest.Create(url);
                WebResponse webresponse;
                try
                {
                    webresponse = (HttpWebResponse)webrequest.GetResponse();
                }
                catch (Exception)
                {
                    return false;
                }
            }
            catch 
            {               
            }
            return true;
        }


IT takes too much time to get respond . Exception occur for Timeout .

how can i make my UI alive ? and make my program faster of getting Respose from any website .


Thank You
Posted

1 solution

You have to execute your operations asynchronous in order to keep your UI responsive.
take a look at the Task Parallel Library[^]
 
Share this answer
 

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