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

  • Home
  • SEARCH
  • 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 7162725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:46:56+00:00 2026-05-28T13:46:56+00:00

I have a quite complex form that presents an option to run a script

  • 0

I have a quite complex form that presents an option to run a script (our own type). Whilst it runs, I don’t want to lock the UI completely, so I would like to start it in a thread. So far so good, but to prevent the user messing with things I need to selectively disable parts of the UI. I could recursively set Enabled = false and then Enabled = true when the thread ends. But this ignores the state of the control at the time of running (ie controls which were disabled for various reasons would be incorrectly re-enabled). Short of building a tree of booleans, is there some other way to block input (such as the GlassPane type in Java)?

  • 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-28T13:46:57+00:00Added an answer on May 28, 2026 at 1:46 pm

    Don’t use DoEvents, it’s evil.

    Use a panel and add all the controls you want to disable in it. When the panel will be disabled, all inner controls will appear to be disabled but the value of their Enabled property won’t be actually modified.

    Here’s a working example:

        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                // Disables UI elements using the panel
                this.SetPanelEnabledProperty(false);
    
                // Starts the background work
                System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(this.Worker));
            }
    
            private void Worker(object state)
            {
                // Simulates some work
                System.Threading.Thread.Sleep(2000);
    
                // Now the work is done, enable the panel
                this.SetPanelEnabledProperty(true);
            }
    
            private void SetPanelEnabledProperty(bool isEnabled)
            {
                // InvokeRequired is used to manage the case the UI is modified
                // from another thread that the UI thread
                if (this.panel1.InvokeRequired)
                {
                    this.panel1.Invoke(new MethodInvoker(() => this.SetPanelEnabledProperty(isEnabled)));
                }
                else
                {
                    this.panel1.Enabled = isEnabled;
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We currently have a quite complex business application that contains a huge lot of
I have created a form, quite complex, with user input unique values, integers and
I have a 3rd party control that is quite complex and takes some time
I have a quite complex View build-up, and as a part of that, I
I have a quite complex helper method that is also needed to be in
I have a quite complex equinox application that I start in Eclipse with a
I have a quite complex xsd file that describe some objects (it's not important,
I have been writing a program that is quite complex compared to what I
I have been working on quite a complex accordion/form recently and have a select
I have quite a large and complex table in a MySQL database that would

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.