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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:47:08+00:00 2026-06-05T02:47:08+00:00

I have a List<int> that I update on every Update() call by calling Add()

  • 0

I have a List<int> that I update on every Update() call by calling Add() to add another integer to that list

On every call to Draw(), I foreach on that List and use the stored int to draw something to the screen.

The problem I have is that the for the first few frames (i.e. few calls to Update), my List is out of sync. The stuff I added never shows up.

I added some tracing to file with this code:

log.WriteLine("start list with count " + Actions.Count);
int nextAction = getNextAction(); // right now this is just some additions
Actions.Add(nextAction);
movelog.WriteLine("end list with count " + Actions.Count);

I get this trace:

start list with count 0
end list with count 1

start list with count 0
end list with count 1

start list with count 0
end list with count 1

start list with count 0
end list with count 1

start list with count 0
end list with count 1

start list with count 1
end list with count 2

start list with count 2
end list with count 3

start list with count 3
end list with count 4

As you can see for the first few calls to this section of the code (i.e. calls to Update()), I add to the list and then the next time it’s called it’s magically gone as if nothing was added to the list. After the fifth time it finally works. This is pretty consistent across runs.

I tried locking on the list object, and I get the exact same behavior.

What is going on with my code? I’m stumped. I’m not doing anything in parallel and I tried tracing the ManagedThreadId every time I add to the list and the thread id is the same.

  • 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-05T02:47:09+00:00Added an answer on June 5, 2026 at 2:47 am

    I’m guessing you’re removing items from the list in the Draw() call, that will give the effect you describe I think because XNA won’t be running 1 Update() method for each Draw() call.

    XNA tries to run Update() 60 times a second by default but the Draw() method tries to run in sync with the monitor refresh rate and will be called less if the update method takes too long.

    Edit
    it seems I was wrong about the Draw() method removing items from the array, the next step I would try while looking for the root of this problem is to make sure nothing is acting on the list out of order would be to change it to a list that logs activities.

    public class LogList<T> : List<T>
        {
            public LogList()
                : base()
            {
                Debug.WriteLine("LogList- Construction");
            }
    
            public new void Add(T item)
            {
                Debug.WriteLine("LogList - Add");
                base.Add(item);
            }
    
            public new void Remove(T item)
            {
                Debug.WriteLine("LogList - Remove");
                base.Remove(item);
            }
    
            public new void RemoveAt(int index)
            {
                Debug.WriteLine("LogLost - RemoveAt");
                base.RemoveAt(index);
            }
    
            public new void Clear()
            {
                Debug.WriteLine("LogList - Clear");
                base.Clear();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have an int list that contains a list of ids. I have
I have a list of objects that have two int properties. The list is
I have a list that gets refreshed every 2 seconds via the Handler postDelayed()
I have some financial data gathered at a List[(Int, Double)], like this: val snp
I have List I want to sort Desc by Priority, which is int and
I have this Java code which is used for JSF pagination: public List<ActiveSessionObj> list(int
In the top Form1 level I have: List<float> cyclicSelectedIndex = new List<float>(2); int currentCyclicIndex;
I have an List<int> which contains 1,2,4,7,9 for example. I have a range from
I have 2 List objects: List<int> lst1 = new List<int>(); List<int> lst2 = new
I have a List where element is: struct element { double priority; int value;

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.