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 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

Ask A Question

Stats

  • Questions 86k
  • Answers 86k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You will want to read about some of the AS3… May 11, 2026 at 5:19 pm
  • Editorial Team
    Editorial Team added an answer In my opinion, a bunch of "ugly" catch blocks IS… May 11, 2026 at 5:19 pm
  • Editorial Team
    Editorial Team added an answer Stick a UNION between them. SELECT COUNT(*) from _users WHERE… May 11, 2026 at 5:19 pm

Related Questions

Good morgning, I would like to be able to analyze text where I am
I want to be able to read from an unsorted source text file (one
Using jQuery, how do I delete all rows in a table except the first?
Does attempting to develop some sort of game, even just as a hobby during

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.