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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:28:34+00:00 2026-05-19T23:28:34+00:00

I know there are various ways to limit how long a task runs under

  • 0

I know there are various ways to limit how long a task runs under .Net and I wondered if there are any others I’ve missed or modifications/improvements to the methods I’ve used previously.

Where I am unclear on how exactly a methodology functions I have included questions on it.

Existing methods I’m aware of though not necessarily used myself:

  1. Create a Thread, poll for it to finish for a certain time then kill the thread. This solution is not great as it relies on ThreadAbortException‘s which are somewhat nasty and if I remember you have no guarantee where you’ll code will exit i.e. it may leave unamanged resources in use etc.
  2. Use the IAsyncResult pattern, the problem with this is that you can wait for a certain amount of time but there isn’t a simple way to signal that you want the request to be aborted so you have to rely on setting a boolean flag (or similar) which is checked for inside the async code and causes it to halt. Issue here is that if the async code is stuck in a certain section of the code it may continue to run for some time before it actually terminates.
  3. I’ve often seen people recommend BackgroundWorker for async stuff but can you use this under ASP.Net (I’d assume so) and does it have a simple way of terminating the async process after a certain time?
  4. Use the Task API in .Net 4.0 (currently all my work is constrained to .Net 3.5 so not an option for me). From a quick read of the MSDN documentation it looks like you can easily cancel a Task using the CancellationToken but how quickly does a cancellation take affect and does it ensure any finally blocks get called.

All solutions/suggestions/methodologies welcome

  • 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-19T23:28:34+00:00Added an answer on May 19, 2026 at 11:28 pm

    The safest form of cancellation is always cooperative.

    I recommend never killing a thread (via ThreadAbortException). If you absolutely have no choice, then make that code a separate process instead, which can be cleanly killed. AppDomains were a nice idea, but they don’t hold up to the real world.

    IAsyncResult, BackgroundWorker, and CancellationToken are all forms of cooperative cancellation. So they are all very clean (not losing resources, calling finally blocks, …), but have the disadvantage that they can’t handle “rogue” code.

    If you are writing the background task code, then just use BackgroundWorker or CancellationToken. If you must work with possibly “rogue” code, then wrap it in a separate process.

    BackgroundWorker will work just fine in ASP.NET, and it supports cooperative cancellation.

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

Sidebar

Related Questions

I know that there are various ways to use PayPal's API (SOAP, etc), but
I know there are some ways to get notified when the page body has
There are various ways to maintain user state using in web development. These are
There are various ways of exiting a process: e.g.: ExitProcess, ExitThread (from the main
We all know the various ways of testing OO systems. However, it looks like
I know this question has been asked a million times in various ways by
I know there is a registry key indicating the install directory, but I don't
I know there are a lot of positive things mod-rewrite accomplishes. But are there
I know there are quite a few line count tools around. Is there something
I know there have been a few threads on this before, but 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.