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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:03:45+00:00 2026-05-21T23:03:45+00:00

If I have a CancellationTokenSource that is still in scope when I’m checking for

  • 0

If I have a CancellationTokenSource that is still in scope when I’m checking for cancellation — e.g., if I’ve just made a database query and have not yet passed the CancellationToken down to Tasks to process the results — should I access IsCancellationRequested from the source or from its token?

In other words, if both options are available, which is preferred, and why?

1:

myCancellationTokenSource.IsCancellationRequested

2:

myCancellationTokenSource.Token.IsCancellationRequested
  • 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-21T23:03:46+00:00Added an answer on May 21, 2026 at 11:03 pm

    In this particular scenario, I believe the two are essentially equivalent. I would prefer using the Token if only because this simplifies refactoring if you later split off the logic checking cancellation from the logic creating the cancellation source. To further that end, I would store the token in a local reference and use that reference for the checking.

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

Sidebar

Related Questions

I currently have an application where I create a series of Tasks that execute
I have a list of work items that need to be processed in order.
I have a search box that works great in WinForms, but is giving me
I have the following code: CancellationTokenSource cancelSource = new CancellationTokenSource(); _cancelTokenList.Add(cancelSource); CancellationToken token =
I have a wpf xbap application that downloads some data in background. There is
Have not done this before, so obviously I suck at it. Here 64 pixels
Have a photography site that I want to prevent image copying from. How can
Have not done this before ( except in java , look how Steve McLeod
I have the following setup in my code that utilizes the TPL: One field
I have the following task cancelSource = new CancellationTokenSource(); token = cancelSource.Token; string strDbA

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.