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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:18:20+00:00 2026-06-01T05:18:20+00:00

I am using Task.Factory.StartNew to make the long processing service calls off the UI

  • 0

I am using Task.Factory.StartNew to make the long processing service calls off the UI thread.However, i am getting the follwing exception as soon as i load the application,

A task’s exception were not observed either by waiting on the Task or accessing its Exception property. As a result the unhandled exception was rethrown by the finalizer thread.

Task.Factory.StartNew(() => this.InitializeViewModel(myViewModel));

private void InitializeViewModel(IModel myViewModel)
{
    lock (viewModelLock)
    {
        myViewModel.MyContext = this.MyContext; // this will set the MyContext property which in turn makes some service calss
    }
}

here i can’t use task.wait() b’coz then it will cause the wait on the UI thread..

how can i avoid this exception??

Thanks.

  • 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-06-01T05:18:21+00:00Added an answer on June 1, 2026 at 5:18 am

    as a first workaround/debugging-help wrap your lock (...) inside a try-catch and set a breakpoint inside the catch-Block – this way you should be able to see the problem

    To the problem with the Task.Wait – you can use the ContinueWith method to get the exceptions:

    var task = Task.Factory.StartNew(() => this.InitializeViewModel(myViewModel));
    task.ContinueWith(o => MyErrorHandler(task.Exception), TaskContinuationOptions.OnlyOnFaulted);
    

    don’t forget the handler:

    void MyErrorHandler(Exception error)
    {
     // handle the exception (log, or whatever)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to specify a Thread's name when using the Task.StartNew method
I just transitioned some of my website's code from using QueueUserWorkItem to Task.Factory.StartNew I
I'm using the following code in my WPF Project : Task.Factory.StartNew( () => {
I have a task to perform an HttpWebRequest using Task<WebResponse>.Factory.FromAsync(req.BeginGetRespone, req.EndGetResponse) which can obviously
I've got a chunk of code that looks like this: var task = Task.Factory.StartNew(()
I've got a chunk of code that looks like this: var task = Task.Factory.StartNew(()
I am using Tasks to run long running server calls in my ViewModel and
I have a method where it need to make multiple service calls and consolidate
In my ViewModel I have this code: Logs = new ObservableCollection<Log>(); Logs = Task.Factory.StartNew(()
This is how i call that error given function var CrawlPage = Task.Factory.StartNew(() =>

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.