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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:11:13+00:00 2026-05-24T06:11:13+00:00

Is there a way to shorten my BackgroundWorker.CancellationPending checkpoint? For example, is there a

  • 0

Is there a way to shorten my BackgroundWorker.CancellationPending checkpoint?

For example, is there a way to encapsulate return like the example code below?:

//REAL CODE (CURRENTLY USE THIS)
if (this.TW.CancellationPending) 
    return; 

//PSEUDO REPLACEMENT CODE
this.CkPt(CurrentMethod); //PSEUDO USAGE 
    //^^^ PARAMETER IS A REFERENCE TO THE CURRENT METHOD, SIMILAR TO `this` FOR AN OBJECT  
//OR MAYBE AN EXTENSION METHOD WOULD LOOK CLEANER
CurrentMethod.CkPt(); //PSEUDO USAGE

private void CkPt(Method m) //PSEUDO METHOD
{
    /*
        POSSIBLY PERFORM OTHER CHECKPOINT TASKS HERE
    */
    if (this.TW.CancellationPending) 
        m.return/*FROM METHOD THAT CALLED ME*/;
}  

I’m trying to make multi-checkpoint situations like this more readable:

//PSUEDO METHOD 
//DO NOT TAKE THIS AS REPEATING CODE
//IT IS ONLY MEANT TO SHOW MULTIPLE USES OF THE SAME CHECKPOINT
//MY REAL TASK METHOD(S) CONTAIN MANY MANY MANY AREAS THAT DON'T REPEAT AND REQUIRE CHECKPOINTS  
public void FakeBWTask()
{
    if (this.TW.CancellationPending) 
        return; 

    foreach (var F1 in Fake1)
    {
        if (this.TW.CancellationPending) 
            return; 

        foreach (var F2 in Fake2)
        {   
            if (this.TW.CancellationPending) 
                return; 
            foreach (var F3 in Fake3)
            {
                if (this.TW.CancellationPending) 
                    return; 
            }
        }
    }
}

Thanks for any help!!

  • 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-24T06:11:14+00:00Added an answer on May 24, 2026 at 6:11 am

    There is no way call for methodA to call methodB and let methodB return methodA (since we don’t have tail recursion)

    Consider using an iterator like this. It will work in some situations where you can put try/catch in-between checkpoints.

    public void FakeBWTask()
    {
       if (this.TW.CancellationPending) 
          return; 
       foreach (object ignore in FakeBWTaskSteps())
       {
          // Other checkpoint logic here....
          if (this.TW.CancellationPending) 
              return; 
       }
    }
    
    private IEnumerable<object> FakeBWTaskSteps()
    {
       Part1();
       yield return null; // Execute checkpoint logic.
    
       Part2();
       yield return null; // Execute checkpoint logic.
    
       Part3();
       yield return null; // Execute checkpoint logic.
    
       Part4();
       yield return null; // Execute checkpoint logic.
    
       // Do some other stuff.
       yield return null; // Execute checkpoint logic.
    
       // final stuff.  No looping here.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering if there is a way to shorten the code below. I
I'm new to ruby. Is there any way how can I shorten this code?
Is there any way to shorten this code: $resultCategoryName = mysql_query(SELECT ecname FROM electioncategorymaster
I am new to vhdl. Is there a way to shorten the following code
Is there a way to shorten this code? NSMutableArray *allobjects = [[NSMutableArray alloc] initWithCapacity:b];
Is there a way to shorten type names in java. Something similar to typedef
All of my string delete's with regex use gsub, is there a shorter way?
Is there a better/shorter way to write the whoAmI method in the following code?
is there way how to get name ov event from Lambda expression like with
I wanted to know if there was a way to shorten this if statement

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.