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

  • Home
  • SEARCH
  • 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 595841
In Process

The Archive Base Latest Questions

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

Ok this may be really simple but everything I try just seems to hit

  • 0

Ok this may be really simple but everything I try just seems to hit a brick wall.

I have a view model with two properties, which are bound to my WPF form:

 bool IsWorking {get;set;}
 ObservableCollection<OtherViewModel> PendingItems {get;set;}

I have a method that I call to fetch some new pending items from outlook, however I also what to show some sort of progress on the form(spinning progress bar), the progress bar visibility is bound to the IsWorking property on the ViewModel, and a grid is bound to PendingItems collection.

I would like to be able to set the IsWorking to true so the UI can show the progress bar, run the work in the background and then set the IsWorking to false after it’s finished so the progress bar goes away.

I created a backgroudworker something like this:

        worker = new BackgroundWorker();
        worker.DoWork += new DoWorkEventHandler(worker_DoWork);
        worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
        worker.RunWorkerAsync();

Now worker_DoWork calls the method that goes of a fetches the pending items and adds them to PendingItems collection, everything runs in the background the UI is still responsive but I get the normal cross threaded error when trying to add to the collection. I wrapped the code that changes the collection in a dispatcher call:

        // Update to show the status dialog.
        Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Render,
                            new Action(delegate()
                            {
                                this.PendingItems.Add(\\Blah);
                            })
                          );

but it still throws the same cross thread error.

I’m not very good with threading so I have no idea what I might be doing wrong, would someone be able to give me a hand with 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-05-13T16:06:25+00:00Added an answer on May 13, 2026 at 4:06 pm

    have a look here for info on how other people have created thread safe observable collections (so you dont have to).

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

Sidebar

Related Questions

This may seem really silly to you, I admit, but when discussing the Model-View-ViewModel
This may be a simple task but at the moment I really have no
I'm just starting out learning C# this may be really simple but in VB
Okay the answer to this may be really simple but I have been searching
OK, this may be really simple, but it is Friday and it has been
This may be a really silly question, but it just crossed my mind and
This may be a really dumb question but I'm just starting to learn the
This may be a really simple question, but I'm trying to create the database
this may be really simple to those in the know-how, but how can i
This one may seem like a simple question, but it's really got me scratching

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.