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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:56:46+00:00 2026-05-22T00:56:46+00:00

In my ViewModel I have this code: Logs = new ObservableCollection<Log>(); Logs = Task.Factory.StartNew(()

  • 0

In my ViewModel I have this code:

Logs = new ObservableCollection<Log>();
Logs = Task.Factory.StartNew(() => mainModel.GetLogs()).Result;

wtih Log being a very simple class with a couple of public properties.

According to my understanding of Task class the mainModel function GetLogs() invoked this way should run on a separate thread and while it is fetching records from the database my UI should be responsive, however that is not what is happening, instead while records are being fetched from the data store my UI is blocked.

I was hoping someone could explain why… TIA.

EDIT: My understading of the Task class was incomplete, using ContinueWith method of the Task class will ensure the async execution as explained below in member replies…

  • 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-22T00:56:47+00:00Added an answer on May 22, 2026 at 12:56 am

    This is because you call Result right after you started the asynchronous operation. The getter of the Result property blocks the execution of current thread until the task is completed.

    Update:

    In order to get the result asynchronously, you need to call ContinueWith and specify a function that will be called when the task is completed:

    Task.Factory.StartNew(() => mainModel.GetLogs()).ContinueWith(t => Logs = t.Result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing WPF applications using MVVM pattern. I have ViewModel with code like this:
I have this code viewModel.Messages = repository.GetAllMessages().OrderBy(x => x.MessageText); with this I am getting
Good Morning, I have the following line of code: var viewModel = new ClassifiedsBrowseViewModel
I have this code in my code-behind file of my View: private string GetSelectedSchoolclassCode()
Before I start, I have this code inside of a Custom Usercontrol: private DependencyProperty
In my view I have this: <TextBlock Text={Binding Title}/> which binds to my ViewModel's
I have this code in my controller for Index view.. public ActionResult Index(int? id)
I have a viewmodel which implement INotifyPropertyChanged . On this viewModel is a property
I have this XAML: <ListBox x:Name=MyItemsList ItemsSource={Binding MyItems} SelectionChanged=ItemsList_SelectionChanged> The code behind assigns the
I have a TextBox.TextProperty bound to a ViewModel property. In the binding I have

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.