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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:34:03+00:00 2026-05-12T23:34:03+00:00

In the following example, how can I get: the button to be disabled-grey the

  • 0

In the following example, how can I get:

  • the button to be “disabled-grey”
  • the message to say “working…”

while the work is being done, not after the work is done?

XAML:

<Window x:Class="TestIsEnabled8938.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <StackPanel Margin="10" HorizontalAlignment="Left">

        <Button x:Name="Button_Refresh" 
                    HorizontalAlignment="Left"  
                    DockPanel.Dock="Top" 
                    Content="Refresh" 
                    Click="Button_Refresh_Click" 
                    Height="25" 
                    Width="200"/>

        <TextBlock x:Name="Message" Text="Button is ready to click."/>
    </StackPanel>
</Window>

code-behind:

using System.Windows;
using System.Threading;

namespace TestIsEnabled8938
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void Button_Refresh_Click(object sender, RoutedEventArgs e)
        {
            Message.Text = "working...";
            Button_Refresh.IsEnabled = false;

            //do work
            Thread.Sleep(2000);

            Message.Text = "Button is ready to click again.";
            Button_Refresh.IsEnabled = true;
        }
    }
}

This doesn’t work either:

Dispatcher.Invoke(new Action(() => { Message.Text = "working..."; }));
Dispatcher.Invoke(new Action(() => { Button_Refresh.IsEnabled = false; }));

Answer:

Thanks Heinzi, this code works:

using System.Windows;
using System.Threading;
using System.ComponentModel;

namespace TestIsEnabled8938
{
    public partial class Window1 : Window
    {
        BackgroundWorker backgroundWorker;

        public Window1()
        {
            InitializeComponent();

            backgroundWorker = new BackgroundWorker();

            backgroundWorker.DoWork += (sender, args) =>
            {
                Thread.Sleep(3000);
            };

            backgroundWorker.RunWorkerCompleted += (sender, args) =>
            {
                Message.Text = "button is ready to click again";
                Button_Refresh.IsEnabled = true;
            };
        }

        private void Button_Refresh_Click(object sender, RoutedEventArgs e)
        {
            Message.Text = "working...";
            Button_Refresh.IsEnabled = false;
            backgroundWorker.RunWorkerAsync();
        }
    }
}
  • 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-12T23:34:04+00:00Added an answer on May 12, 2026 at 11:34 pm

    If you want the UI to update (and stay responsive) while your task is running, you need to use a separate thread, for example by using a BackgroundWorker.

    Code example (untested):

    BackgroundWorker bwButtonWorker;
    
    public Window1() {
        InitializeComponent();
    
        bwButtonWorker = new BackgroundWorker();
    
        bwButtonWorker.DoWork += (sender, args) => {
            // do your lengthy stuff here -- this happens in a separate thread
            Thread.Sleep(2000);
        }
    
        bwButtonWorker.RunWorkerCompleted += (sender, args) => {
            // this happens in the UI thread, so you can modify your UI elements here
            Message.Text = "Button is ready to click again.";
            Button_Refresh.IsEnabled = true;
        }
    }
    
    private void Button_Refresh_Click(object sender, RoutedEventArgs e)
    {
        Message.Text = "working...";
        Button_Refresh.IsEnabled = false;
        bwButtonWorker.RunWorkerAsync();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone tell me please why the following example work in Firefox but not
In the following example i can create an object dynamically via a string; however,
How can I subset the following example data frame to only return one observation
How can I remove the unwanted whitespace in following example? Note 1. that there
Can anybody help me with retrieving some elements from the following example text: sdfaasdflj
For example the following cast can be found littered throughout the MSDN documentation: (LPTSTR)&lpMsgBuf
I have a URL which can be any of the following formats: http://example.com https://example.com
Can anyone give me an example of how I can consume the following web
How can you sort the following word by the given rule? Example data is
In the following example I get title from this form using html id=title .

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.