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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:29:04+00:00 2026-06-08T18:29:04+00:00

I am able to access the list ( ListData ) value from within its

  • 0

I am able to access the list (ListData) value from within its class, but if I try to reference the list from outside of the class, it shows it as an empty list.

I add objects to ListData in the getVideoList method.

I added this piece of code and it works now (Polling method) , Is this ineffiencient ?

 IAsyncResult result = request.BeginGetResponse(new AsyncCallback(getVideoList), state);
            while (result.IsCompleted == false)
            {
               Thread.Sleep(1000);
             }

Public class otherclass{
    static void main(string [] args){
      RestProcess process = new RestProcess(videoListURI);
      process.initilaizeRest();

      foreach (VideoSeriesElement ele in process.ListData)
      {
        Console.WriteLine(ele.id);
        Console.WriteLine(ele.title);
        Console.WriteLine(ele.href);
        Console.WriteLine(ele.image);
      }

      Console.ReadLine();
  }

}

public class RestProcess
{
    /// <summary>
    /// Default constructor
    /// </summary>
    /// 
    readonly string blankimage = "http://images1.test.com/properties/NoThumbnail_HD.jpg";
    public RestProcess(string uri)
    {
        URI = uri;
        ListData = new ObservableCollection<VideoSeriesElement>();
    } 
    public ObservableCollection<VideoSeriesElement> ListData{get;set;}


    public void initilaizeRest()
    {
        WebRequest request = HttpWebRequest.Create(URI);
        request.Method = "GET";

        // RequestState is a custom class to pass info to the callback
        RequestState state = new RequestState(request, URI);
        IAsyncResult result = request.BeginGetResponse(new AsyncCallback(getVideoList), state);
    }

    public string URI{get;set;}

    /// <summary>
    /// getVideoList
    /// </summary>
    /// <param name="result"></param>
    public void getVideoList(IAsyncResult result)
    {
        RequestState state = (RequestState)result.AsyncState;
        WebRequest request = (WebRequest)state.Request;
        HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);

        try
        {
            TextReader textreader = new StreamReader(response.GetResponseStream()); 
            XDocument doc = XDocument.Load(textreader);


            foreach(XElement videoSeriesEle in doc.Descendants("video-series"))
            {
                var videseriesEle = new VideoSeriesElement();    
                videseriesEle.id = videoSeriesEle.Attribute("id").Value;
                videseriesEle.href = videoSeriesEle.Attribute("href").Value;
                videseriesEle.title = videoSeriesEle.Element("title").Value;

                if (!videoSeriesEle.Element("images").IsEmpty && videoSeriesEle.Element("images").Elements("image") != null)
                {
                    var imagelist = videoSeriesEle.Element("images").Elements("image").ToList();
                    foreach (var ele in imagelist)
                    {
                        if (ele.Attribute("styleid").Value.Equals("5"))
                        {
                            if (videoSeriesEle.Element("images").Element("image").Attribute("href").Value != null)
                            {
                                videseriesEle.image = videoSeriesEle.Element("images").Element("image").Attribute("href").Value;
                            }

                        }
                    }

                }
                else { videseriesEle.image = blankimage; }


                //add object to list 
                ListData.Add(videseriesEle);

            }

            //Close streams 
            textreader.Close();
            response.Close();
        }
        catch (XmlException e)
        {
            Console.WriteLine(e);
        }

    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="state"></param>
    /// <param name="timedOut"></param>
    private static void ScanTimeoutCallback(object state, bool timedOut)
    {
        if (timedOut)
        {
            RequestState reqState = (RequestState)state;
            if (reqState != null)
                reqState.Request.Abort();
            Console.WriteLine("aborted- timeout");
        }
    }
}
  • 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-08T18:29:05+00:00Added an answer on June 8, 2026 at 6:29 pm

    The RestProcess.initilaizeRest() method requests the data via an IAsyncResult, meaning the call to get the data is asynchronous. In your otherClass class, you attempt to process and loop through the ListData element immediately after calling initilaizeRest() and there is a very good chance that the data is not loaded yet.

    To fix this, you should have a callback/event-handler in the otherClass that listens for when the data is populated.

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

Sidebar

Related Questions

I want to be able to access properties from a JSON string within my
I would like to be able to access data:post.labels from within the header at
I need to be able to access a list throughout my Rails project. For
I'd like to be able to access GPS and Camera devices from websites built
How do all! I want to be able to access a value in a
How about using this API? developers.google.com/google-apps/documents-list It seems to be able to access the
I am developing one android application which select wifi access point from list of
I have a requirement where I need to be able to access a list
I need my app to be able access an third party API who limits
I need to be able to access a property via reflection, and, knowing that

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.