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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:37:43+00:00 2026-05-23T23:37:43+00:00

I have a function which isn’t so complicated, but for some reason, each time

  • 0

I have a function which isn’t so complicated, but for some reason, each time I call it, it freezes the screen for like quarter of a second. This function is on a timer and is deployed every second so it can get pretty annoying to the user.

The function basically gets a screen shot of the screen, checks if the screen that it’s looking for by comparing 10 pixels and returns true if that’s the screen or false otherwise :

ClassName.CheckScreen(CaptureScreen(),ClassName.Pxarr1); //Capture screen isn't the problem. It gave me no freezes in an endless loop.

Thats the class :

class ClassName
{
    public static Pixel[] Pxarr1 = new[]
    {
        new Pixel(Color.FromArgb(255, 204, 204, 170), new Point(15, 145)),
        new Pixel(Color.FromArgb(255, 221, 204, 187), new Point(20, 460)),
        new Pixel(Color.FromArgb(255, 221, 204, 187), new Point(20, 545)),
        new Pixel(Color.FromArgb(255, 204, 187, 170), new Point(15, 150)),
        new Pixel(Color.FromArgb(255, 221, 204, 187), new Point(22, 190)),
        new Pixel(Color.FromArgb(255, 204, 204, 187), new Point(25, 540)),
        new Pixel(Color.FromArgb(255, 204, 187, 153), new Point(22, 61)),
        new Pixel(Color.FromArgb(255, 221, 204, 170), new Point(23, 563)),
        new Pixel(Color.FromArgb(255, 204, 187, 153), new Point(23, 47)),
        new Pixel(Color.FromArgb(255, 204, 204, 187), new Point(23, 463)),

    };

    public static Pixel[] Pxarr2 = new[]
    {
        new Pixel(Color.FromArgb(255, 221, 255, 119), new Point(80, 120)),
        new Pixel(Color.FromArgb(255, 51, 119, 221), new Point(180, 525)),
        new Pixel(Color.FromArgb(255, 204, 170, 85), new Point(630, 455)),
        new Pixel(Color.FromArgb(255, 85, 153, 17), new Point(707, 177)),
        new Pixel(Color.FromArgb(255, 255, 153, 34), new Point(520, 440)),
        new Pixel(Color.FromArgb(255, 255, 238, 51), new Point(150, 325)),
        new Pixel(Color.FromArgb(255, 0, 85, 255), new Point(455, 70)),
        new Pixel(Color.FromArgb(255, 255, 221, 51), new Point(685, 285)),
        new Pixel(Color.FromArgb(255, 17, 17, 17), new Point(547, 369)),
        new Pixel(Color.FromArgb(255, 170, 170, 136), new Point(500, 545)),

    };

    public static Pixel[] Pxarr3 = new[]
    {
        new Pixel(Color.FromArgb(255, 238, 238, 238), new Point(353, 223)),
        new Pixel(Color.FromArgb(255, 28, 33, 49), new Point(428, 198)),
        new Pixel(Color.FromArgb(255, 85, 85, 85), new Point(462, 314)),
        new Pixel(Color.FromArgb(255, 221, 221, 238), new Point(450, 450)),
        new Pixel(Color.FromArgb(255, 102, 102, 102), new Point(384, 349)),
        new Pixel(Color.FromArgb(255, 204, 204, 204), new Point(406, 248)),
        new Pixel(Color.FromArgb(255, 221, 221, 221), new Point(464, 453)),
        new Pixel(Color.FromArgb(255, 255, 204, 17), new Point(413, 198)),
        new Pixel(Color.FromArgb(255, 204, 204, 204), new Point(343, 447)),
        new Pixel(Color.FromArgb(255, 255, 255, 255), new Point(403, 457)),

    };

    public static Pixel[] Pxarr4 = new[]
    {
        new Pixel(Color.FromArgb(255, 204, 170, 136), new Point(120, 227)),
        new Pixel(Color.FromArgb(255, 221, 187, 153), new Point(502, 170)),
        new Pixel(Color.FromArgb(255, 119, 85, 34), new Point(692, 243)),
        new Pixel(Color.FromArgb(255, 238, 221, 187), new Point(211, 169)),
        new Pixel(Color.FromArgb(255, 187, 170, 136), new Point(272, 238)),
        new Pixel(Color.FromArgb(255, 170, 153, 119), new Point(696, 64)),
        new Pixel(Color.FromArgb(255, 136, 85, 17), new Point(306, 242)),
        new Pixel(Color.FromArgb(255, 187, 170, 119), new Point(115, 236)),
        new Pixel(Color.FromArgb(255, 204, 187, 153), new Point(310, 183)),
        new Pixel(Color.FromArgb(255, 153, 102, 34), new Point(647, 245)),

    };

    public static Pixel[] Pxarr5 = new[]
    {
        new Pixel(Color.FromArgb(255, 255, 238, 221), new Point(376, 150)),
        new Pixel(Color.FromArgb(255, 255, 238, 221), new Point(376, 350)),

        new Pixel(Color.FromArgb(255, 255, 238, 221), new Point(506, 150)),
        new Pixel(Color.FromArgb(255, 255, 238, 221), new Point(506, 350)),

        new Pixel(Color.FromArgb(255, 255, 238, 221), new Point(246, 150)),
        new Pixel(Color.FromArgb(255, 255, 238, 221), new Point(246, 350))
    };

    public static bool CheckScreen(Bitmap img, Pixel[] samples)
    {
        int verifiedpixels = 0;
        for (int i = 0; i < samples.Length; i++)
        {
            Color c = img.GetPixel(samples[i].Location.X, samples[i].Location.Y);
            if (c == samples[i].Color)
                    verifiedpixels++;
        }
        return verifiedpixels >= (samples.Length * 0.6);
    }

}

Note : A 100 loop for statement was twice as slow with CaptureScreen() than with an image from a file.
(4 seconds vs 2 seconds)

But still, I don’t understand why this function casuses any freezing, even with an image from a file.

  • 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-23T23:37:43+00:00Added an answer on May 23, 2026 at 11:37 pm

    Since you are using a timer, it should not freeze the UI, unless you are using System.Windows.Forms.Timer which will execute its call back on the UI thread. Instead use System.Timers.Timer or System.Threading.Timer.
    Example for System.Timers.Timer:

    private System.Timers.Timer _checkPixelsTimer = new System.Timers.Timer();

    public Form1()
    {
        InitializeComponents();
    
        _checkPixelsTimer.Intervla = 1000;//one second
        _checkPixelsTimer.AutoReset = true;
        _checkPixelsTimer.Elapced += OnCheckPixelsTimerElapced;
        _checkPixelsTimer.Start();
    }
    
    private void OnCheckPixelsTimerElapced(object sender, System.Timer.ElapcedEventArgs e)
    {
        if (ClassName.CheckScreen(CaptureScreen(),ClassName.Pxarr1))
        {
            MethodInvoker method = new MethodInvoker(() => { /*code that relays on the UI thread */ });
            if (this.InvokeRequired)
            {
                this.Invoke(method); 
            }
            else
            {
                method();
            }
        }
    }
    

    Edit: update the code to preview how to call a function at the UI thread.

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

Sidebar

Related Questions

We have a function in our code which isn't being called, but should be.
I have an function which decodes the encoded base64 data in binary data but
I have a function called goRight() which does some stuff when I click a
I have like 50 different php files which all use the mail function. After
I have written a small function in C# which isn't my main launguage so
I have this function which uses SSE2 to add some values together it's supposed
I'm dealing with some pre-ANSI C syntax. See I have the following function call
I have a pretty complicated function which does a couple of AJAX posts on
i have a tween function which fades in a display object over time. when
I have a function which parses one string into two strings. In C# 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.