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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:17:16+00:00 2026-05-11T13:17:16+00:00

I am having fun with WPF and got a problem. I have googled and

  • 0

I am having fun with WPF and got a problem. I have googled and found this website that has the same problem of me but without any working solution.

The problem is that I have a button that do some processing of data (around 30 sec). I want to have the button to disable and to have log writing in a text box… the problem is that it doesn’t disable and it doesn’t wrote any thing on the textbox until the processing is completely done.

Any idea?

 private void button1_Click(object sender, RoutedEventArgs e)  {         this.button1.IsEnabled = false;         //Long stuff here          txtLog.AppendText(Environment.NewLine + 'Blabla');         //End long stuff here         this.button1.IsEnabled = true;  } 
  • 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. 2026-05-11T13:17:16+00:00Added an answer on May 11, 2026 at 1:17 pm

    As others have said, use the BackgroundWorker or some other method of doing work asychronously.

    You can declare it under your Window, initialize it somewhere like the Loaded event, and use it in the Click event. Here’s your method, modified to use BackgroundWorker, assuming you’ve declared it under the Window as _bw:

    private void Window_Loaded(object sender, RoutedEventArgs e) {     _bw = new BackgroundWorker();     _bw.DoWork += new DoWorkEventHandler((o, args) =>     {         //Long stuff here                this.Dispatcher.Invoke((Action)(() => txtLog.AppendText(Environment.NewLine + 'Blabla')));     });      _bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler((o, args) =>     {         //End long stuff here         this.Dispatcher.Invoke((Action)(() => this.button1.IsEnabled = true));     }); }  private void button1_Click(object sender, RoutedEventArgs e) {     this.button1.IsEnabled = false;      _bw.RunWorkerAsync(); } 

    Note that anything that modifies your UI from another thread must be done within a Dispatcher.Invoke or Dispatcher.BeginInvoke call, WPF does not allow you to get or set DependencyProperty values from any thread but the one where the object was created (more about this here).

    If you wanted to read from txtLog instead of modifying it, the code would be the same:

    //Long stuff here        this.Dispatcher.Invoke((Action)(() =>  {     string myLogText = txtLog.Text;     myLogText = myLogText + Environment.NewLine + 'Blabla';     txtLog.Text = myLogText; })); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is strange but I'm just having fun. I am attempting to
So I have been having lots of fun playing with SIMILE Timeline , but
I am somewhat new to jQuery but have been having fun trying learn about
So, I've been having fun with this web site that creates random themes for
I'm playing with Google Go and I'm having fun (!), but I'm having some
I’m having fun with EF and have come unstuck. Originally I used the following
I'm an amateur, admittedly so, but I'm having fun trying to learn a little
I'm having a problem with custom cursors in a WPF application. I use the
Thanks to a suggestion from Chas. Owens , I have been having fun playing
I'm having fun with Razor today! Can you see what is wrong with this

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.