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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:46:49+00:00 2026-05-28T19:46:49+00:00

Given the following RX code: static void Main(string[] args) { int x = 0;

  • 0

Given the following RX code:

    static void Main(string[] args)
    {
        int x = 0;
        const int timerMilliseconds = 1000 * 30; //30 seconds
        var disposable = Observable.Generate(0, i => true, i => 1, i => 1, i => TimeSpan.FromMilliseconds(1))
            .Subscribe(i => Interlocked.Increment(ref x));

        var timer = new Timer(o =>
                                  {
                                      disposable.Dispose();
                                      Console.WriteLine("Disposed of observable. Current total: " + x);
                                  }, null, timerMilliseconds, timerMilliseconds);


        Console.ReadKey(true);
        timer.Dispose();
    }

If I run this code, the output after 30 seconds (on my machine) is ~1924, which is kind of surprising to me. I would have expected that with a delay of one millisecond, after 30 seconds the number should be closer to ~30,000. It must be something obvious, but what am I missing here?

  • 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-28T19:46:50+00:00Added an answer on May 28, 2026 at 7:46 pm

    I think you are forgetting that the Windows operating system doesn’t give you a hard guarantee that the generating and/or observing thread will be scheduled to run within the next millisecond. Depending on the state of your system some overhead wrt to context switching might be involved as well. On my rusty old laptop I didn’t manage to get below ~20 ms. (I measured the time between invocations of the “Subscribe” lambda with the help of a Stopwatch.)

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

Sidebar

Related Questions

Given the following code... class Program { static void Main(string[] args) { Foo foo
Ok, consider the following code: private const int THRESHHOLD = 2; static void Main(string[]
public class Main { public static void main (String args[]) { int nums[]= {2,
Given the following code: class C { static void m(String s) { ... }
Given the following code: using (var client = new WebClient()) { string url =
Given the following code sample: public class WeirdStuff { public static int doSomething() {
Given the following code, I try to implement the public static Point operator +(int
Given the following code: using System; namespace Sandbox { class CommandLine { static void
Given the following code: var people = new List<person>(){ new person { Name =
Given the following code: int *a = NULL; a = calloc(1, sizeof(*a)); printf(%d\n, 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.