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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:57:08+00:00 2026-05-12T08:57:08+00:00

The system I’m working on needs to consume an IEnumerable of work items, iterate

  • 0

The system I’m working on needs to consume an IEnumerable of work items, iterate through each of them, and in between them wait for a certain period of time. I would like to keep the system as simple as possible at the enumeration site. That is, I’d like to have a method that I can call at the end of the foreach block which will block for the specific amount of time I specify – but I don’t want to use Thread.Sleep because it’s impossible to guarantee precision.

The minimum amount of time I’ll need to block for is 100ms, but I don’t want it to block any longer than this, which I’ve seen Thread.Sleep do on occasion (I assume because of the time taken in context switches, etc).

Edit: Related; does a call to WaitHandle.Wait with a timeout value do the same thing as Thread.Sleep?

  • 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-12T08:57:09+00:00Added an answer on May 12, 2026 at 8:57 am

    Why exactly do you need to wait while enumarating?

    If a IEnumerable collection changes while you’re going through it you’ll get an exception so as a matter of fact no items can be added or removed by other threads while you thread is working on it.

    Given that, why the artificial delay? Just consume it as it comes and let the scheduler distribute the work among your threads.

    If you want a really really precise wait time I suggest you use a Thread.Sleep(time – 20 ms) and then busy wait for the right time do your work.

    Only real time operating system can give you such precision. You can assume Thread.Sleep has a precision of about 20 ms so you could, in theory sleep until the desired time – the actual time is about 20 ms and THEN spin for 20 ms but you’ll have to waste those 20 ms. And even that doesn’t guarantee that you’ll get real time results, the scheduler might just take your thread out just when it was about to execute the RELEVANT part (just after spinning)

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

Sidebar

Related Questions

System.BitArray only implements the non-generic IEnumerable, which returns an Object for the IEnumerator.Current property.
System.out.println(matcher.group(1)); System.out.println(matcher.group()); I like to know what's the difference between the above two codes.
System.IO.Path in .NET is notoriously clumsy to work with. In my various projects I
System.Text.RegularExpressions.Regex(#*#) is this correct..!? my text can be like #abc1234+as00# etc. ie, anything between
System.Collections.Concurrent has some new collections that work very well in multithreaded environments. However, they
System.out.println(s.toString().substring(0,s.indexOf(.mp3))); i am downloading file from android application.. i need to name them as
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
System.setProperty(java.library.path, pathToLibs); doesn't work because it seems either java.library.path is read only or JVM
The system I work is a little more complex to explain here but I
System.Environment.OSVersion does not appear to indicate which Edition of Windows 2003 is installed (Standard,

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.