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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:50:36+00:00 2026-06-04T13:50:36+00:00

There are times that a method needs to be run several times until it

  • 0

There are times that a method needs to be run several times until it validates. In my case there are expressions like bar.Name.Equals("John Doe") which I want to run and run until this expression validates.

Something like:

bool succeeded = TryUntillOk(bar.Name.Equals("John Doe"), 15, 100);

where TryUntillOk would be a method that runs this expression 15 times with a sleep of 100ms between each call.

I read this excellent list of answers to similar issues but in my case there is no standar delegate that this TryUntillOk method would accept.

The title of the question is not constructive. Feel free to edit it 🙂

  • 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-06-04T13:50:37+00:00Added an answer on June 4, 2026 at 1:50 pm

    You are probably looking for something like this:

    bool TryRepeatedly(Func<bool> condition, int maxRepeats, TimeSpan repeatInterval)
    {
        for (var i = 0; i < maxRepeats; ++i)
        {
            if (condition()) return true;
            Thread.Sleep(repeatInterval); // or your choice of waiting mechanism
        }
        return false;
    }
    

    Which would be invoked as follows:

    bool succeeded = TryRepeatedly(() => bar.Name.Equals("John Doe"),
                                   15,
                                   TimeSpan.FromMilliseconds(100));
    

    The only interesting part here is that you specify the condition as a Func<bool>, which is a delegate to a method that takes no parameters and returns a boolean. Lambda expression syntax allows you to trivially construct such a delegate at the call site.

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

Sidebar

Related Questions

In Javascript is there a function that returns the number of times that a
In a recent discussion on ORMs for webapps someone mentioned that there are times
There are lots of times Eclipse can't connect to emulator that I turned on
Is there MS SQL Server function that counts the number of times a particular
I have a class that refers to UiApplication.getUiApplication() multiple times, would there be any
Someone told me that the Frobenius pseudoprime algorithm take three times longer to run
I have a PHP script that needs to run some pretty hefty imagemagick commands.
Is there a way to debug a function that is defined dynamically in run
I've heard it said several times that if you need to dynamically downcast then
Is there a standard Java interface with a getName() method that returns a string?

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.