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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:29:33+00:00 2026-05-24T16:29:33+00:00

I designed a WPF application based on MVVM pattern and I need to get

  • 0

I designed a WPF application based on MVVM pattern and I need to get large amount of data from a webservice, and i do it with a BackgroundWorker inside the ViewModel. To modify the observable collection i have to use a dispatcher and the problem is here, even if i pass by reference UI Dispatcher it dosen’t work, it is like I use the inner dispatcher and my application get freezed until all data are retrived.

I try to get the UI Dispatcher in several ways, Dispatcher.CurrentDispatcher, Application.Dispatcher, App.Current.Dispatcher… doing some researches I read that it should be works, does someone have any suggestions?

Thank you
Marco

Update

Here some code: This is how I pass the Dispatcher to the ModelView

void AppWindow_Loaded(object sender, RoutedEventArgs e)
{
     this.DataContext = new ModelViewApplication(System.Windows.Threading.Dispatcher.CurrentDispatcher);
}

Then I try to get data in this way

public ModelViewApplication(Dispatcher _dispatcher)
{
    BackgroundWorker bw = new BackgroundWorker();
    bw.DoWork += new DoWorkEventHandler(getData);
    bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(completedData);

    bw.RunWorkerAsync();
}

public void getData(object sender, DoWorkEventArgs e)
{
    _dispatcher.Invoke(DispatcherPriority.Normal,
        new Action(
            delegate()
                 {
                 //Connect to webservice and retrieve data
                 ....
                 }));
}

It seems like the multithread dosen’t work

  • 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-24T16:29:33+00:00Added an answer on May 24, 2026 at 4:29 pm

    Use the BackgroundWorker to get your data, then use the RunWorkerCompleted to update the ObservableCollection. You shouldn’t need the Dispatcher at all

    public ModelViewApplication()
    {
        BackgroundWorker bw = new BackgroundWorker();
        bw.DoWork += new DoWorkEventHandler(getData);
        bw.RunWorkerCompleted += completedData;
    
        bw.RunWorkerAsync();
    }
    
    public void getData(object sender, DoWorkEventArgs e)
    {
        //Connect to webservice and retrieve data
        e.Result = WebService.GetData();
    }
    
    private void completedData(object sender, RunWorkerCompletedEventArgs e)
    {
        MyCollection = new ObservableCollection<SomeClass>((IList)e.Results);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm taking an vanilla WPF application and converting it to use the MVVM pattern.
I'm developing a networked WPF application with the MVVM pattern and it seems that
I have a database designed to hold card data from various trading card games.
We have created a beautifully designed .NET WPF desktop application. We are installing the
I'm using Microsoft's new WPF ribbon (October 2010 release) and I designed my application
I'm building a WPF application that is designed to act as a notification toolbar
I need to add functionality to my WPF application (in C#) that allows users
In a database-centric application that is designed for multiple clients, I've always thought it
I made a little WPF application with a SQL CE database. I built the
I'm looking for opinion on using Canvas vs. Grid panels in WPF. I need

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.