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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:50:48+00:00 2026-05-19T10:50:48+00:00

I have an application whereby I download and process approximately 7,800 URL’s using a

  • 0

I have an application whereby I download and process approximately 7,800 URL’s using a Paraller.ForEach() loop. Using this technique has allowed my computer to complete this operation in about 4.5 minutes (is used to take almost 28 minutes on average).

As this is running inside a WinForms application I allow the user to “stop” the process early by simply clicking a stop button, which will in turn set a volatile boolean variable to ‘false’. At the top of my Parallel.ForEach() loop I check the state of that variable, and if it has been set to ‘false’ I simply call the ParallelLoopState.Stop() method. My next code block inside the loop only runs if the ParallelLoopState has not been stopped.

Works great. Have experienced zero problems using this implementation for the 3 weeks I’ve been using it.

But I was just reading and came across the “CancellationTokenSource” and “CancellationToken” classes and discovered these were designed to essentially perform the same act … to allow a Parallel loop to be cancelled externally.

Can anyone tell me if they foresee a problem with me continuing to use my existing implementation?

Parallel.ForEach(searchList, (url, state) =>
{
    if (!this.isSearching)
    {
        state.Stop();

        OnSearchEvent(new SearchStatusEventArgs(SearchState.STOP_REQUESTED, ......));
    }

    if (!state.IsStopped)
    {
        // continue on with regular processing .......
    }
});
  • 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-19T10:50:48+00:00Added an answer on May 19, 2026 at 10:50 am

    Looks fine to me! The CancellationTokenSource and CancellationToken are really for use with Tasks especially where tasks are linked together via ContinueWith. From there, you can interrogate the Token (thread safe) and throw an exception or quit the thread in exactly the same way you are already doing it.

    Unless you go down the route of complicated task chaining and closures, then I’d say there is no need to complicate things!

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

Sidebar

Related Questions

We have a ASP .Net application whereby we use Log4Net to log details within
I have developed a C# WinForms application whereby the user is providing input via
Overflowed Stack, I have a Java web application (tomcat) whereby I allow the user
I have created a basic ASP.NET membership application, whereby users can login to view
I have an rails a application whereby it has a page that contains a
I have an application I'm building in ColdFusion, whereby all requests will run through
I have a application whereby a user can destroy other users attached to the
I have a requirement for an ASP.NET web application whereby the same user is
I have a situation whereby an application we use has many databases used for
I have an application whereby I dynamically create controls on a form from a

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.