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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:14:05+00:00 2026-05-27T02:14:05+00:00

Following Jason Dolinger video I’ve crated DispatchingWcfModel that decorates normal model. But I don’t

  • 0

Following Jason Dolinger video I’ve crated DispatchingWcfModel that decorates normal model. But I don’t understand why do I need it. Should I always use some kind of Dispatching model? What if I will use normal model instead of dispatching model? Why do I need “Dispatcher”?

class DispatchingWcfModel : IWcfModel
{

    private readonly IWcfModel _underlying;
    private readonly Dispatcher _currentDispatcher;

    public DispatchingWcfModel(IWcfModel model)
    {
        _currentDispatcher = Dispatcher.CurrentDispatcher;
        _underlying = model;
        _underlying.DataArrived += _underlying_DataArrived;
    }

    private void _underlying_DataArrived(List<ConsoleData> obj)
    {
        Action dispatchAction = () =>
        {
            if (DataArrived != null)
            {
                DataArrived(obj);
            }
        };
        _currentDispatcher.BeginInvoke(DispatcherPriority.DataBind, dispatchAction);
    }

    public List<ConsoleData> DataList
    {
        get { throw new NotImplementedException(); }
        set { throw new NotImplementedException(); }
    }

    public event Action<List<ConsoleData>> DataArrived;
}
  • 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-27T02:14:06+00:00Added an answer on May 27, 2026 at 2:14 am

    TL;DR: DispatchingWcfModel class wrap up injected IWcfModel and guarantee that when a new data comes – changes would be dispatched to UI in safe way event IWcfModel.DataArrived event has been raised in background thread, so DispatchingWcfModel always pushes callback using Dispatcher to the UI Thread.

    More detailed: In your example DispatchingWcfModel class subscribing to an event of injected IWcfModel, so when event has been raised – event handler _underlying_DataArrived would be called and what most important point – it would be called on the thread which actually raising an event so it is possible that calling thread would not be a UI Thread so any changes to UI controls would be failed, to avoid this Dispatched is used.

    In WPF Dispatcher is useful when you need to update UI elements so this should be done in UI Thread. Right way to do this – delegate this work to Dispatcher which persitsting a queue of workitems (requests) which should be performed on the UIThread.

    MSDN:

    In WPF, a DispatcherObject can only be accessed by the Dispatcher it
    is associated with. For example, a background thread cannot update
    the contents of a Button that is associated with the Dispatcher on the
    UI thread. In order for the background thread to access the Content
    property of the Button, the background thread must delegate the work
    to the Dispatcher associated with the UI thread. This is accomplished
    by using either Invoke or BeginInvoke. Invoke is synchronous and
    BeginInvoke is asynchronous. The operation is added to the queue of
    the Dispatcher at the specified DispatcherPriority.

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

Sidebar

Related Questions

Take the following JSON string (generated by some ExtJS code - but that's irrelevant):
I'm following the racetrack example from Jason Rudolph's book at InfoQ , using grails-1.2.1.
Given the following table id parentID name image 0 0 default.jpg 1 0 Jason
I am getting the following error when trying to attach an object that is
Every-time I create or update a model in my Rails app, the following output
I want to form a pattern to match the word Jason in the following
XML structure: <Emp> <Employee username=John/> <Employee username=Jason/> </Emp> I don't want to insert the
I was following up Jason Dentler's series of posts on how to use NHibernate
I have the following query method that has slow performance: @Override public Map<String, Long>
I have the following Array = [Jason, Jason, Teresa, Judah, Michelle, Judah, Judah, Allison]

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.