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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:44:19+00:00 2026-06-06T03:44:19+00:00

To quote Marc Gravell: ///…blah blah updating files string newText = abc; // running

  • 0

To quote Marc Gravell:

///...blah blah updating files
string newText = "abc"; // running on worker thread
this.Invoke((MethodInvoker)delegate {
    someLabel.Text = newText; // runs on UI thread
});
///...blah blah more updating files

I’m looking to do this with WPF so can’t use the invoke method. Any thoughts? This Threading stuff is doing my head in :/

MORE DETAIL

I began my new Thread like so

Thread t = new Thread (LoopThread);
t.Start();
t.Join();

But throughout LoopThread, I want to write to the UI.

UPDATE

Thanks to Jon Skeet for the Dispatcher.Invoke bit. Seems MethodInvoker is WinForms also. WPF equivalent?

UPDATE 2

Thanks Adriano for suggesting instead of System.Windows.Forms.MethodInvoker, using System.Action.

(You guys were right about the this parameter confusion, just need to build to remove errors.)

Bus since adding the SimpleInvoke, now I’m hit with

Extension method must be defined in a non-generic static class

on the line

public partial class MainWindow : Window

Any thoughts?

  • 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-06T03:44:22+00:00Added an answer on June 6, 2026 at 3:44 am

    In WPF, you just use Dispatcher.Invoke instead of Control.Invoke.

    The DispatcherObject class (which WPF classes derive from) exposes a Dispatcher property, so you just need:

    Dispatcher.Invoke((Action) delegate {
        someLabel.Text = newText; // runs on UI thread
    });
    

    If you’re using C# 3 or higher (and .NET 3.5 or higher) you might want to add an extension method to DispatcherObject:

    // Make this a new top-level class
    public static class DispatcherObjectExtensions
    {
        public static void SimpleInvoke(this DispatcherObject dispatcherObject,
                                        Action action)
        {
            dispatcherObject.Dispatcher.Invoke(action);
        }
    }
    

    So you can just use:

    // From within your UI code
    this.SimpleInvoke(() => someLabel.Text = newText);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A quote from MSDN Assigning an instance of this type is not thread safe
Quote from Wikipedia : A public key token. This is a 64-bit hash of
thestring = urllib.quote(thestring.encode('utf-8')) This will encode it. How to decode it?
I'm trying to fix single quote bug in the code: std::string Index; connection->Open(); String^
How can I escape a ' (single quote) in HTML? This is where I'm
To quote PHP: Anonymous functions are currently implemented using the Closure class. This is
for (String stock : allStocks) { Quote quote = getQuote(...); if (null == quoteLast)
How should I quote this: <tr onclick=$.colorbox({href:'information1.html'});> When put in an echo ; ?
String quote = Now is the time for all good + men to come
The following quote is from this link: http://apidocs.meego.com/1.2-preview/qtmobility/qgeopositioninfosource.html#createDefaultSource Creates and returns a position source

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.