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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:01:01+00:00 2026-05-24T11:01:01+00:00

I am writing an application using C#. I ran some benchmarks to try and

  • 0

I am writing an application using C#. I ran some benchmarks to try and speed up my application and came accross a problem. I have a loop which needs to run multiple times at separate intervals:

Process[] processes = Process.GetProcesses();
foreach (Process process in processes)
    if (process.MainWindowTitle == "Title")
    {
        // Do Stuff
    }

I realized that the problem is, as soon as I create the array, accessing a specific element of that array takes significantly longer than subsequent access.

if (processes[0].MainWindowTitle == "Title") { } // ~0.5 ms
if (processes[0].MainWindowTitle == "Title") { } // ~0.0 ms
if (processes[0].MainWindowTitle == "Title") { } // ~0.0 ms
if (processes[0].MainWindowTitle == "Title") { } // ~0.0 ms

This is quite a significant problem. Something that should be taking less than 0.1ms is taking 50ms. Why is this happening and what can I can do to speed things up?

  • 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-24T11:01:02+00:00Added an answer on May 24, 2026 at 11:01 am

    It’s not accessing the array which is slow – it’s getting the MainWindowTitle property, which I believe is lazily populated. When you first ask for it, it’s doing all the OS gubbins to fetch the value.

    To test this, try:

    if (processes[0] != null)
    

    which I think you’ll find will be very fast right from the start.

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

Sidebar

Related Questions

I have problem concerning python packages and testing. I'm writing an application using wx
I am writing an application using Symfony. I have some reusable components that I
im writing an application using Visual Studio 2010 Express Edition. I have a problem
I am writing an application using cocoa which, in some point (surprise), opens window.
I am writing an application using C# and I would like to read some
I'm writing an application using Seam 2.2.x which will be deployed on JBoss 5.1.
I'm writing some integration tests using a robot. I have the robot opening a
I am writing application using PhoneGap on Android. I need to call some PhoneGap
I am writing an application using jQuery (with the jPlayer plugin) that needs to
Writing a Java application using the Play framework and need some HTTP-Live streaming. I

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.