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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:29:14+00:00 2026-06-03T06:29:14+00:00

The below code is very simplified. I’m trying to abstract a dispatcher context so

  • 0

The below code is very simplified. I’m trying to abstract a dispatcher context so my view models can synchronize events that can only be raised on the GUI thread.

There’s a circular reference in this pattern. Is there any other way to create a DispatcherObject? Am I doing it wrong?

I’ve read other questions like this, but the answers all seem to involve a reference to the DispatcherObject in the ViewModel. Is this an acceptable place for a circular reference?

class ViewModel {
    public DispatcherObject Dispatcher { get; set; }
}

class ModelView : UserControl {

    ModelView() {
        InitializeComponent();
        DataContext = new ViewModel { Dispatcher = this };
    }
}
  • 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-03T06:29:15+00:00Added an answer on June 3, 2026 at 6:29 am

    Generally speaking, circular references are something you want to avoid. Here are two alternatives:

    1. Grab the dispatcher statically

    The quick and dirty approach. Very easy to do, will work fine almost all of the time, but as with anything else done statically it does not lend itself to testability (which may or may not be a problem). In the rare instance where your WPF app has more than one UI thread you won’t be able to use this approach blindly.

    WPF: var dispatcher = Application.Current.Dispatcher;

    Silverlight: var dispatcher = Deployment.Current.Dispatcher;

    2. Make the dispatcher a dependency of the ViewModel

    Configure your dependency injection container appropriately and have the Dispatcher be a dependency for those ViewModels that need to access it. This approach is more hassle but it allows you to work with multiple UI threads, is testable, and in general has all the usual pros/cons of doing things with DI.

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

Sidebar

Related Questions

I have some very simple code below that I can't get to validate on
I have written a very simple WCF service, that worked fine (code below), then
I've placed some very basic code below of what I'm trying to do. I
The below code is very simple. I have a jQuery autocomplete bound to an
I am having a very specific problem in JQuery The code below is used
below code is my databasehandler class i got it from a tutorial. Beside that
This may be very obvious question, pardon me if so. I have below code
I have the below code that links and runs fine in 32bit mode -
The code below works very well for resizing an image by aspect ratio by
In the simplified code below, if(city == New York City) { var MyObject =

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.