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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:55:16+00:00 2026-05-27T06:55:16+00:00

I would like to create a subclass of DispatcherObject to create my own thread-affined

  • 0

I would like to create a subclass of DispatcherObject to create my own thread-affined objects with a message queue, like WPF uses for UI elements.

I have a test app that runs without crashing, but the DispatcherObject doesn’t seem to be processing its message queue. I just created a new blank WPF application and added this code to the MainWindow.xaml.cs:

public partial class MainWindow : Window {
    public MainWindow() {
        InitializeComponent();

        DispatcherWorker worker = null;
        ManualResetEventSlim latch = new ManualResetEventSlim(false);

        new Thread(() => {
            worker = new DispatcherWorker();
            latch.Set();
        }).Start();

        latch.Wait();

        // worker.Dispatcher.Thread is stopped by here... why?
        worker.Dispatcher.BeginInvoke(new Action(() => {
            // This code never executed
            worker.DoWork(this);
        }));
    }
}

public class DispatcherWorker : DispatcherObject {

    public void DoWork(MainWindow window) {
        VerifyAccess();
        window.Dispatcher.BeginInvoke(new Action(() => window.Background = Brushes.Black));
    }
}

The DoWork() method is never executed, and if I put a breakpoint just before the call to BeginInvoke, I see that the Dispatcher’s thread is stopped. Why is it stopped? Am I setting up the thread wrong?

(This similar question seems to have the same problem, but the accepted answer says to run the code in a GUI application, which will have a message pump. But I’m getting the same problem even when running in a GUI app.)

  • 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-27T06:55:17+00:00Added an answer on May 27, 2026 at 6:55 am

    The thread that owns the Dispatcher will need to “pump” that Dispatcher. That is, it will need to be told to process messages queued via that Dispatcher. To do this, you use a DispatcherFrame:

    Dispatcher.PushFrame(new DispatcherFrame());
    

    This should appear after you set your latch. That thread will never exit – it will just pump messages on that thread’s dispatcher. If you want it to have an exit condition, see the documentation for the DispatcherFrame Continue property.

    Note that it’s irrelevant whether you’re using your custom DispatcherWorker class or some other built-in WPF class. If there’s nothing pumping the Dispatcher on that thread, no messages will be processed.

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

Sidebar

Related Questions

I would like to create a subclass of UIActionSheet that uses blocks instead of
I would like to create my own subclass of UIImage that would allow me
i would like create a array of structure which have a dynamic array :
I am looking to create a Custom UIButton (not subclass) progrmatically, I would like
I'd like to create a subclass of UIAlertView to implement my own defaut behaviors
I have class Dad with subclass Son . I'd like to create a subclass
In WPF I would like to create custom Inline implementation. From documentation of Inline
I would like to subclass an immutable type or implement one of my own
i would like to create a custom View (subclass of the View class) and
I would like to create some instance variables for my model subclass, but when

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.