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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:57:36+00:00 2026-05-13T21:57:36+00:00

I have an application that needs to check a website feed every second. Sometimes

  • 0

I have an application that needs to check a website feed every second.

Sometimes the request to the server is longer than a second. In this case, the application needs to wait until the first request completes, then start a new request immediately. How could I implement this?

Also, the request should not freeze the GUI.

  • 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-13T21:57:36+00:00Added an answer on May 13, 2026 at 9:57 pm

    I would use a simple variation of the producer-consumer pattern. You’d have two theads, a producer and a consumer, that share an integer variable. The producer would have a System.Threading.Timer that fired every second, at which time it would Interlocked.Increment the variable and call the consumer. The consumer logic repeatedly checks the feed and Interlocked.Decrement the counter, while the counter is greater than zero. The consumer logic would be protected by a Monitor.TryEnter which would handle re-entrancy. Here’s sample code.

    public static FeedCheck{
      int _count = 0;
      static object _consumingSync = new object();
      static Threading.Timer _produceTimer;
    
      private static void Consume() {
        if (!Monitor.TryEnter(_consumingSync)) return;
    
        try {
          while(_count > 0) {
            // check feed
            Interlocked.Decrement(ref _count);
          }
        }
        finally { Monitor.Exit(_consumingSync); }
      }
    
      private static void Produce() {
        Interlocked.Increment(ref _count);
        Consume();
      }
    
      public static void Start() {
        // small risk of race condition here, but not necessarily
        // be bad if multiple Timers existed for a moment, since only
        // the last one will survive.
        if (_produceTimer == null) {
          _produceTimer = new Threading.Timer(
            _ => FeedCheck.Produce(), null, 0, 1000
          );
        }
      }
    }
    

    Usage:

    FeedCheck.Start();
    

    A good resource on .NET Threading (besides the MSDN Library stuff) is Jon Skeet’s documentation, which includes this example of producer-consumer under “More Monitor methods”.

    By the way, a true producer-consumer pattern revolves around a collection of work data, with one or more threads producing work by adding data to that collection, while one or more other threads consumer work by removing data from that collection. In our variation above, the “work data” is merely a count of the number of times we need to immediately check the feed.

    (Another way to do it, instead of having the timer callback call Consume, is for the timer callback to lock and pulse a Monitor that Consume waits on. In that case, Consume has an infinite loop, like while(true), which you kick off one time in its own thread. Therefore there is no need to support re-entrancy with the call to Monitor.TryEnter.)

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

Sidebar

Ask A Question

Stats

  • Questions 342k
  • Answers 342k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Windows doesn't support it. But you easily add it yourself.… May 14, 2026 at 5:12 am
  • Editorial Team
    Editorial Team added an answer This code should be placed inside a view controller that… May 14, 2026 at 5:12 am
  • Editorial Team
    Editorial Team added an answer Without a working test case, it is hard to know… May 14, 2026 at 5:12 am

Related Questions

I have an application where the contents of e-mails that get sent are stored
I've written an application in Microsoft Visual C# 2008 Express Edition. The Windows XP
I'm writing a web application in Python, intended for use by teachers and pupils
I want to make a windows mobile 6 cellphone application. This application will talk
Our company has an intranet with 30,000+ web pages and 160+ web applications. This

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.