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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:18:26+00:00 2026-06-03T00:18:26+00:00

Here you have a simple WPF program: <!– Updater.xaml –> <Window x:Class=Update.Updater xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml

  • 0

Here you have a simple WPF program:

<!-- Updater.xaml -->
<Window x:Class="Update.Updater"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <Grid>
        <StackPanel>
            <Button Click="Button_Click" Height="50"></Button>
            <Label Content="{Binding Label1Text}" Height="50"></Label>
            <Label Content="{Binding Label2Text}" Height="50"></Label>
        </StackPanel>
    </Grid>
</Window>

// Updater.xaml.cs
using System.Threading;
using System.Windows;

namespace Update
{
    public partial class Updater : Window
    {
        public Updater()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Label1Text = "It is coming...";
            Thread.Sleep(3000);
            Label2Text = "It is here!";
        }

        public string Label1Text
        {
            get { return (string)GetValue(CategoryProperty); }
            set { SetValue(CategoryProperty, value); }
        }

        static readonly DependencyProperty CategoryProperty = DependencyProperty.Register("Label1Text", typeof(string), typeof(Updater));

        public string Label2Text
        {
            get { return (string)GetValue(Label2TextProperty); }
            set { SetValue(Label2TextProperty, value); }
        }

        static readonly DependencyProperty Label2TextProperty = DependencyProperty.Register("Label2Text", typeof(string), typeof(Updater));
    }
}

The intention is that when you click the button, the first label displays It is coming.... Then the program sleeps for 3 seconds, and finally the second label displays It is here!. However, the naïve implementation below doesn’t work. If you run it and click the button the following happens: The program sleeps for 3 seconds, and then the two label texts are displayed simultaneously. Do you know how to correct the program so that it does as intended?

  • 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-06-03T00:18:27+00:00Added an answer on June 3, 2026 at 12:18 am

    Button_Click is invoked by the UI thread, and you should not do anything requiring more than a few miliseconds in it, let alone sleeping for 3 seconds. Messages are not processed during that time, your interface is unresponsive, and your application is considered "hung" by the system.

    So, that long processing task should be handled by another thread.

    Something like that (untested):

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Label1Text = "It is coming...";
    
        var backgroundWorker = new BackgroundWorker();
    
        backgroundWorker.DoWork += (s,e) => { Thread.Sleep(3000); }
        backgroundWorker.RunWorkerCompleted += (s,e) => { Label2Text = "It is here!"; }
        backgroundWorker.RunWorkerAsync();
    }
    

    Links:

    BackgroundWorker

    Build More Responsive Apps With The Dispatcher

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

Sidebar

Related Questions

Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
Here's my hypothetical example. I have a very simple WPF window with a one
I'm trying to learn WPF, so here's a simple question, I hope: I have
I have this simple js tabs. Here is the html : <div class=product-collateral> <div
I have a really strange problem with WPF. A simple window with a button
Here I have a simple php script which displays some values from a database
I have simple algorithm that clean the whitespace from half string until end. Here
Have a simple form (only extract fields here) but for some reason the JQserilization
I have a simple Jquery function here: function submit_selection(del,submit) { del='yes'; submit=true; var ITAMZ=new
I have a simple situation here. lets face html code first => <form name=geoKey

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.