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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:10:45+00:00 2026-05-14T07:10:45+00:00

I have a winform with some buttons that are updated in an event handler.

  • 0

I have a winform with some buttons that are updated in an event handler. The event is fired from a background thread, then the appearance is set via the Invoke method. The buttons will just get enabled or disabled. Something will happen at unpredicable times, though:

  • The button will not change appearance visually. When it should be enabled, it still looks like it’s disabled
  • Clicking on the “disabled” button still fires the click event – as if its actually enabled underneath
  • After resizing or moving the form, the component’s appearance is set correctly to enabled.
  • Only the components that are updated in this manner are affected. Other components on the form look/behave fine.

Here is how the button is getting updated in code:

public class Form1 :Form
{
     void eventFromThread(object sender, CustomEventArgs e)
     {
           if(e.enable)   RunOnUiThread(ShowEnabledView);
           else RunOnUiThread(ShowDisabledView);
     }

     void ShowEnabledView()
     {
          button1.Enabled = true;
     }

     void ShowDisabledView()
     {
          button1.Enabled = false;
     }

     void RunOnUiThread(MethodInvoker method)
     {
          try
          {
                if(InvokeRequired)
                {
                     Invoke(method); 
                }
                else
                     method.Invoke();
           }
           catch(ObjectDisposedException)
           { return;}
           catch(InvalidOperationException)
            {return;}
     }
}

I have tried forcing a refresh on the button, and it hasn’t re-occurred yet, but its only been a couple of days. The issue just seems to pop up when it wants to, so I can’t really be sure I’m fixing anything. Can anyone shed any light on this?

  • 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-14T07:10:46+00:00Added an answer on May 14, 2026 at 7:10 am

    try calling

    System.Windows.Forms.Application.DoEvents()
    

    after you change the button’s Enabled property

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

Sidebar

Related Questions

I have applications(WinForm) that gets some objects from webservice. After receiving array I transform
Currently I have some buttons on my Winform that need to be disabled/enabled at
Some event handlers for the WinForm DataGridView have DataGridViewCellEventArgs as a parameter and a
I have some buttons on a Winform app, and using the following code have
-Hello, looking for some help. We currently have a winform app used to do
I have a windows installer project which installs some software (winform, service, mce addin).
I have a Winforms application that schedules some work using a service. The service
I have a WinForms application that requires some configuration which I do at install
Updated to be clear. Step One: I have a XML file that I want
In my C# app I get an xml from a server that contains some

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.