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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:31:37+00:00 2026-05-20T10:31:37+00:00

Suppose a lot of stuff is happening on the main GUI thread (data flowing

  • 0

Suppose a lot of stuff is happening on the main GUI thread (data flowing in, user actions, etc.). Suppose we would like to create a form and show it.

Could there be a performance boost if we use Application.Run(Form) as opposed to Form.Show()? Is there a better way to do this? Please explain why or why not.

  • 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-20T10:31:37+00:00Added an answer on May 20, 2026 at 10:31 am

    Do not use Application.Run() unless you know what it does. And, once you know what it does, you’ll know why you shouldn’t use it except at the beginning of the program.

    Application.Run starts a message pump. This is the heart of any GUI program, and what enables the window to recieve messages, which allows it to fire events and do stuff. You cannot have two message pumps, as that doesn’t make any sense.

    (Yes, I know that you can have two message pumps, but why would you ever want to? It’s hard enough having one pump!)

    As to your real question (how do I not do stuff on my GUI thread), that’s a bit more complicated. The simplest answer is “use threads”. since I don’t know the particulars of your situation, I can only give some general advice:

    1. Do not try to manipulate controls from other threads. At best, it won’t work. At worst, it will set your house on fire (okay, maybe not that bad. But, don’t do it.). Instead, you need to Invoke methods. An example will be provided below.

    2. Do not run long running processes on your GUI thread. Short things are okay, but anything that might take longer than half a second are probably best offloaded to another thread.

    3. Use events to communicate from your Worker thread back to your GUI thread.

    Here is an example of how to run a worker thread:

    delegate void VoidDelegate();
    
    List<int> results;
    bool cancelWork = false;
    
    void DoWork() {
        int calc;
        results = new List<int>();
    
        for(int i = int.MinValue ; i < int.MaxValue; i+=10) {
            if(cancelWork) break;
            results.Add(i);
        }
    
        this.Invoke(new VoidDelegate(WorkFinished));
    }
    
    void Button1_Click(object sender, EventArgs e) {
        button1.Enabled = false;
        button2.Enabled = true;
        cancelWork = false;
        Thread t = new Thread(DoWork);
        t.Start();
    }
    
    void Button2_Click(object sender, EventArgs e) {
        button2.Enabled = false;
        cancelWork = true;
    }
    
    void WorkFinished() {
        button1.Enabled = true;
        button2.Enabled = false;
        textBox1.Text = results.Count.ToString();
    }
    

    Obviously, this is a contrived example, however it serves my purpose.

    This hypothetical form contains two buttons, button1 (“Run”) and button2 (“Cancel”), and a text box, textbox1. button2 should start out disabled (Enabled = false).

    While the worker thread it running, the user can interact with any other controls, including the “Cancel” button (button2 in my example). Once it finishes, it Invokes the WorkFinished function, which displays the results (and otherwise cleans up state).

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

Sidebar

Related Questions

Suppose I have a script that does a lot of stuff, and doesn't work
Suppose my C++ program has outputted a lot of stuff to the terminal, say
Suppose, I have a lot of classes, which are constructed using Java reflection (for
Suppose we have the name written in any none-latin letters - languages, like Arabic,
Suppose I created index with descending order CREATE INDEX `MyTable.MyIndex` USING BTREE ON `MyTable`
I have a lot of multithreading bugs since I introduced a second worker thread.
I would like to solve the following problem using constraints but i actually don't
Suppose I have a data array, dat <- array(NA, c(115,45,248)) Q1: What I do
I'm a reasonably intelligent guy and have been involved in a lot of stuff
Suppose I have ViewModel like public class AnotherViewModel { public string Name { get;

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.