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 6553397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:34:37+00:00 2026-05-25T12:34:37+00:00

I have a listview which I populate from a webservice query. Problem is that

  • 0

I have a listview which I populate from a webservice query. Problem is that if the http query is slow due to network or the URL is wrong then the query freezes the UI for a bit. So my question is how do I throw this off to a side process and populate the list in the background?

Here is how I get the data and it usually sits for 30 secs or more at request.GetResponse(); I get JSON back and parse that but this function is the hold up and would like to wrap it in something. So how would I do that specifically?

public static String get(String url) {

    StringBuilder sb = new StringBuilder();

    // used on each read operation
    byte[] buf = new byte[32768];

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.Method = "POST";
    request.Timeout = 10000;

    HttpWebResponse response;
    try {
        response = (HttpWebResponse)request.GetResponse();
    } catch (WebException we) {
        return "ERROR!"
    }
    Stream resStream = response.GetResponseStream();

    ... read from stream and parse 

}

#### Using suggestion of Worker Thread ############

This doesn’t work either.

// create new thread
new Thread(new ThreadStart(myTable) ).Start();

inside the myTable method using an anonymous delegate I thought might be the best way.

private void myTable() {
    if (this.InvokeRequired) {
        this.Invoke(new EventHandler(delegate(object obj, EventArgs a) {
        // do work here
        String url = "http://someurl....";
        // Set the view to show details.
         listView1.View = View.Details;

        // Display check boxes.
        listView1.CheckBoxes = false;

        // Select the item and subitems when selection is made.
        listView1.FullRowSelect = true;
        listView1.Items.Clear();
        listView1.Columns.Clear();

        listView1.Columns.Add(Resources.MainColumn0, 20, HorizontalAlignment.Left);
        listView1.Columns.Add(Resources.MainColumn1a, 250, HorizontalAlignment.Left);
        listView1.Columns.Add(Resources.MainColumn2, 150, HorizontalAlignment.Left);

        try {
           // Call the function mentioned above to get the data from the webservices....
           string users = get(urlUsers);
 .............
  • 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-05-25T12:34:37+00:00Added an answer on May 25, 2026 at 12:34 pm

    Use a worker thread to make the query, the use Control.Invoke to update the UI or use an async call to get the data from the service. Without knowing more about exactly how you’re getting the data and doing population, that’s about as detailed as I can get.

    EDIT

    Your attempt at offloading the work to a thread is subverted by your call to Invoke, which moves everything back to the UI thread. You need to do something along these lines:

    private void MyThreadProc()
    {
        // get the data from the web service here
    
        this.Invoke(new EventHandler(delegate
        {
            // update your ListView here
        }));
    }
    

    Note that the long-running part of the command is not contained within the Invoke call.

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

Sidebar

Related Questions

I have a following problem. I have a ListView which returns data from SQL
I have an app with a large ListView which is terribly slow so I'm
I have an activity that extends ListView. I populate my list with the results
I have a listview which is populated by a SimpleCursorAdapter that is binding data
I have a listview that's populated by rows that get their data from a
i have a ListView which contains objects bound from an collection. The representation of
I have a listview which loads its data from sqlite database. Each row in
I have a radiobutton group in Android that I populate with data from a
I have a ListView which is populated by a SQLite query in OnCreate using
I have a problem with ListView. the thing is that when I click on

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.