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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:56:41+00:00 2026-06-13T02:56:41+00:00

I currently have a program that intercepts some packets, does some modification/adding classes to

  • 0

I currently have a program that intercepts some packets, does some modification/adding classes to lists based on the information and sends it on.

What I am currently doing is when I add an item I lock the list I’m adding to whilst I add it. However I have a PictureBox which draws information from the lists every 50ms or so. Currently the way I do it looks something like this:

Graphics g = e.Graphics;

lock (Core.Collections.SpaceStations)
{
    foreach (Classes.Station station in Core.Collections.SpaceStations)
    {
        Image img;
        switch (station.Company)
        {
            case 1:
                img = Prog.Properties.Resources.mmo_station;
                break;
            case 2:
                img = Prog.Properties.Resources.eic_station;
                break;
            case 3:
                img = Prog.Properties.Resources.vru_station;
                break;
            default:
                img = new Bitmap(50, 50);
                break;
        }
        g.DrawImage(img, (float)((station.Position.x - 750) / Core.CurrentMap.ByX), (float)((station.Position.y - 750) / Core.CurrentMap.ByY), 35, 35);
    }
}

As you can see, it locks for the entire length of the iteration which causes my packet handler to block until it finishes painting and can cause lag for both the server and client (because I lock before adding or removing items in the packet handler). My question is would it be quicker to copy all the items from the List into a temporary list inside the lock and then draw them all outside the lock from the temp list? Mainly my question is, is it faster to iterate through a list or to copy a list.

  • 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-13T02:56:42+00:00Added an answer on June 13, 2026 at 2:56 am

    I think copying the list is better option here.

    It will defiantly improve the performance but would be memory intensive, which can be handled to an extend by properly disposing the list after drawing.

    Station[] stations = Core.Collections.SpaceStations.ToArray();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a program that finds and edits HTML files based on finding
I currently have a basic chat program in c++ that uses WinSock2.h with UDP.
I have a python program that I am currently working on which is working
We have an app that currently installs itself into 'program files\our app', and it
Currently I have a program that takes as input a folder that contains .MPP
currently I have a disfigured avi file that a program of mine creates. I
I currently have a program that basically reads html from a webpage. After sending
I currently have a multi-threaded program that crawls websites and writes their text to
I currently have a c++ Linux program that reads a parameter P from a
Currently I have a program that takes pictures and saves them as a jpg

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.