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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:33:29+00:00 2026-05-27T08:33:29+00:00

When I run the code after the form is initialized, it works the way

  • 0

When I run the code after the form is initialized, it works the way I intended. But, when I load it for the first time in the form Load event it lags the UI from drawing for a second. I don’t really want to make a splash screen as there’s already some UI elements that indicate work is being done.

volatile bool ABfired = false;
    public form_Main()
    {
        InitializeComponent();
    }

    void GetSearchableDataCache()
    {
        this.UIThread(() =>
        {
            ultraActivityIndicator1.AnimationEnabled = true;
            ultraLabel_Status.Text = "Querying SQL...";
        });

        var projids = new List<string>();
        var names = new List<string>();

        ABfired = false;

        Thread A = (new Thread(() =>
        {
            while (!ABfired)
            {
            }
            projids = new sql.ProjectIDs(true).Get();
        })
        {
            Name = "Thread A", IsBackground = true
        });
        Thread B = (new Thread(() =>
        {
            while (!ABfired)
            {
            }
            names = new sql.names(true).Get();
        })
        {
            Name = "Thread B", IsBackground = true
        });

        Thread AB = (new Thread(() =>
        {
            ABfired = true;
            while (A.IsAlive || B.IsAlive)
            {
            }
            this.UIThread(() =>
            {
                ultraActivityIndicator1.AnimationEnabled = false;
                ultraLabel_Status.Text = "Ready";
            });
        })
        {
            Name = "Thread AB", IsBackground = true
        });

        A.Start();
        B.Start();
        AB.Start();
    }

private void form_Main_Load(object sender, EventArgs e)
    {
        GetSearchableDataCache();
    }
  • 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-27T08:33:30+00:00Added an answer on May 27, 2026 at 8:33 am

    Your threads are spinning, so they each use up an entire CPU core.
    That slows the system down dramatically.

    You should never wait using a while loop like you’re doing now.
    Instead, wait on a ManualResetEvent.

    However, you can replace all of that code with much a simpler implementation using Tasks and no explicit threads.
    Using Task.ContinueWith will allow you to run a task after the previous one finishes without wasting a thread.

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

Sidebar

Related Questions

I want to run some code after my form is resized. However, the following
I want to run some code in this context after the form created here
Python 2.5.1 http://www.cgsecurity.org/wiki/After_Using_PhotoRec I've just run PhotoRec and the code given as a way
I have code that I run when my form runs (I tried below InitializeComponent();
For some reason, the code below fails on the second line with run-time error
I'm trying to add a blur event to some form elements which will run
how can i run code when an application ends with asp.net mvc ?
i need run code that will create a database and populate tables. i am
Our product contains a task-manager system that allows applications to run code in a
As a best practice, do you run code analysis on both debug and release

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.