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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:58:45+00:00 2026-05-24T10:58:45+00:00

I am building a Windows Service with .NET 4.0. I have various unhandled exceptions

  • 0

I am building a Windows Service with .NET 4.0.

I have various unhandled exceptions thrown in Tasks, but they do not terminate my process as the MSDN documentation states (Parallel Tasks – see Unobserved Task Exceptions).

“If you don’t give a faulted task the opportunity to propagate its
exceptions (for example, by calling the Wait method), the runtime will
escalate the task’s unobserved exceptions according to the current
.NET exception policy when the task is garbage-collected.”

It behaves like this even when I use the most simple invokation of a task:

Task.Factory.StartNew(() => { throw new Exception(); } 

The service keeps on running fine when that is called.

According to the docs, the finalizer of the Task will rethrow the exception once the Task is GC’d but this does not appear to happen. MSDN states repeatedly that normal “.NET exception policy” results in process termination.

Why doesn’t this terminate my app? The only thing I can think is there is somehow a reference to the task held somewhere (is it the lambda??)

  • 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-24T10:58:47+00:00Added an answer on May 24, 2026 at 10:58 am

    From Essential C# 4.0, page 715, the following might help you out:

    The unhandled exception during the Task’s execution will be suppressed
    until a call to one of the task completion members: Wait(),
    Result,Task.WaitAll(), or Task.WaitAny(). Each ot these members will
    throw any unhandled exceptions that occurred within the task’s
    execution.

    Quite a few ways of handling exceptions are available. Have a look at MSDN here.

    In answer to your comment, another quote from the same book explains why some exceptions are not propagated:

    Although relatively rare, one of the exceptions for the general rule
    (of bubbling up) happens to be on Task. [..] Any Task-based exceptions
    thrown from the finalization queue during application exit will go
    suppressed. The behavior is set this way because frequently the effor
    to handle such an exception it too complex […]

    To overcome this, one way to do this elegantly is to create an exception handler task and to use ContinueWith to follow up after your task runs. You can then use parentTask.IsFaulted and gracefully crash, even in the event the exception is thrown in the finalization queue during application exit.

    Tip: use the the flag OnlyOnFaulted to have this task run only when an exception occurs.

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

Sidebar

Related Questions

I have created a Windows Service in VB.net for building xML from a database.
I'm building a Windows service and following this MSDN article , but I'm stuck
I am building a WCF service interface for an existing Windows service process. The
i am trying to make a setup of windows service.but when i was building
I'm building a windows service but I would like to get some web pages
I'm currently building a Windows Service which needs to process a queue of messages
I'm building a Windows Forms form in C# with various elements in a panel
I'm building a Windows Forms application where I have a menuStrip and a toolStripMenuItem
I'm building a Windows Service app that has configuration data stored in App.Config. However,
I wanted a windows service I'm building to run overnight. So I changed my

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.