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

The Archive Base Latest Questions

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

In this example I want to add a .loop({quantity},{sleepvalue}) to a method I got

  • 0

In this example I want to add a .loop({quantity},{sleepvalue}) to a method

I got it to work with this:

this.loop(count, 500,
  ()=>{
   var image = Screenshots.getScreenshotOfDesktop();
   pictureBox.load(image);
   images.Add(image);
   updateTrackBar();
  });

using this extension method:

public static void loop(this Object _object, int count, int delay, MethodInvoker methodInvoker)
  {
   for(int i=0; i < count; i++)
   {
    methodInvoker();
    _object.sleep(delay);
   }
  }

which means that the invocation syntax is:

this.loop(15,500, () => {...code...});

but ideally what I wanted to do was something like:

()=> { ...code...}.loop(10,500);

which doesn’t work unless I do it like this:

new MethodInvoker(()=>{...code...}).loop(10,500);

which will work with this version of the extension method:

public static void loop(this MethodInvoker methodInvoker, int count, int delay)
  {
   for(int i=0; i < count; i++)
   {
    methodInvoker();
    Processes.Sleep(delay);
   }
  }
  • 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-13T16:51:25+00:00Added an answer on May 13, 2026 at 4:51 pm

    No, unfortunately there isn’t.

    I blogged about this quite a while ago 🙁

    However, with the right choice of indentation, you can make it look almost identical to a normal loop:

    HelperType.Loop(count, 500, () =>
    {
       // Code here
    });
    

    That’s what a lot of the Parallel Extensions samples look like

    I wouldn’t make it an extension method on something you’re not actually going to use, just so that you can use “this” instead of the real type name… not unless you’ve got a real use for the object it’s called “on”, anyway.

    (I’d also suggest following .NET naming conventions – make your methods PascalCase.)

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

Sidebar

Related Questions

for example, I want to add this to jsfiddle.net jQuery Validation is this possible?
I want to add my ul & li every two loop.. Example <?php while
I want to draw a widget (in this example, a canvas) and then remove
Ideally I want a function something like the following (this example doesn't compile): void
In this example I create three buttons 'one' 'two' 'three'. When clicked I want
looking at this example of the jquery ui slider http://jqueryui.com/demos/slider/#steps i want to be
In this simple example, i want to create a String array populated with each
I have this URL example.com/photo?people I want to rewrite this URL in the form
I want to get 100 and example from this string ?connect:100/username:example/ I searched in
I want to subscribe to a facebook page for example with this url ,http://www.myurl.com

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.