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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:16:23+00:00 2026-05-17T15:16:23+00:00

my view model creates a BackgroundWorker in its constructor. BackgroundWorker updates the model’s properties

  • 0

my view model creates a BackgroundWorker in its constructor. BackgroundWorker updates the model’s properties from its DoWork event handler. The code below is a contrived example (ViewModelBase is taken almost verbatim from the MVVM paper).


public class MyViewModel : ViewModelBase
{
    public int MyProperty
    {
        get
        {
            return this.my_property;
        }
        private set
        {
            if (this.my_property != value)
            {
                this.my_property = value;
                this.OnPropertyChanged("MyProperty");
            }
        }
    }

    public MyViewModel()
    {
        this.worker = new BackgroundWorker();
        this.worker.DoWork += (s, e) => { this.MyProperty = 1; };
        this.worker.RunWorkerAsync();
    }
}

my view is bound to this view model:


public partial class MyPage : Page
{
    public MyPage()
    {
        InitializeComponent();
        this.DataContext = new MyViewModel();
        }
}

the problem is that my application crashes intermittently when my page is displayed. this definitely has something to do with the worker thread and data binding in XAML. it seems that if i start the worker from inside the Loaded event handler for the page, the problem goes away but since it is hard to reproduce consistently, i am not sure whether this is the right fix.

does any one have any suggestions or ideas what might be the exact cause?

EDIT: i only can reproduce it if i run it without a debugger. and the error in the system log is InvalidOperationException thrown from ShowDialog, which is not much help. under the debugger it runs fine.

thanks for any help
konstantin

  • 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-17T15:16:24+00:00Added an answer on May 17, 2026 at 3:16 pm

    It might have to do with updating the UI from a background thread, but WPF is supposed to handle this for you:
    Making sure OnPropertyChanged() is called on UI thread in MVVM WPF app

    Read this too: http://www.wintellect.com/CS/blogs/jlikness/archive/2009/12/16/dispatching-in-silverlight.aspx

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

Sidebar

Related Questions

Is there good example code or a test project for explaining the Model–view–presenter (MVP)
Under the View-Model-ViewModel pattern for WPF, I am trying to databind the Heights and
WPF's view model oriented way of doing things makes it very tempting to just
In Model-View-Presenter pattern where should we write validations of user input.
I am using the Model-View-Presenter pattern for a web page. Should the presenter be
A simple question: I have a Model-View-Controller setup, with Models accessing a SQL database.
What are the alternative design methods to the Model View Controller? MVC seems to
I'm trying to implement a WPF application using MVVM (Model-View-ViewModel) pattern and I'd like
I'm working on a WPF application and is using the Model-View-ViewModel pattern. The application
I am trying to adapt a simple WPF application to use the Model-View-ViewModel pattern.

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.