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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:54:17+00:00 2026-05-31T14:54:17+00:00

I have a requirement to fire off web service requests to an online api

  • 0

I have a requirement to fire off web service requests to an online api and I thought that Parallel Extensions would be a good fit for my needs.

The web service in question is designed to be called repeatedly, but has a mechanism that charges you if you got over a certain number of calls per second. I obviously want to minimize my charges and so was wondering if anyone has seen a TaskScheduler that can cope with the following requirements:

  1. Limit the number of tasks scheduled per timespan. I guess if the number of requests exceeded this limit then it would need to throw away the task or possibly block? (to stop a back log of tasks)
  2. Detect if the same request is already in the scheduler to be executed but hasn’t been yet and if so not queue the second task but return the first instead.

Do people feel that these are the sorts of responsibilities a task scheduler should be dealing with or am i barking up the wrong tree? If you have alternatives I am open to suggestions.

  • 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-31T14:54:19+00:00Added an answer on May 31, 2026 at 2:54 pm

    I agree with others that TPL Dataflow sounds like a good solution for this.

    To limit the processing, you could create a TransformBlock that doesn’t actually transform the data in any way, it just delays it if it arrived too soon after the previous data:

    static IPropagatorBlock<T, T> CreateDelayBlock<T>(TimeSpan delay)
    {
        DateTime lastItem = DateTime.MinValue;
        return new TransformBlock<T, T>(
            async x =>
                    {
                        var waitTime = lastItem + delay - DateTime.UtcNow;
                        if (waitTime > TimeSpan.Zero)
                            await Task.Delay(waitTime);
    
                        lastItem = DateTime.UtcNow;
    
                        return x;
                    },
            new ExecutionDataflowBlockOptions { BoundedCapacity = 1 });
    }
    

    Then create a method that produces the data (for example integers starting from 0):

    static async Task Producer(ITargetBlock<int> target)
    {
        int i = 0;
        while (await target.SendAsync(i))
            i++;
    }
    

    It’s written asynchronously, so that if the target block isn’t able to process the items right now, it will wait.

    Then write a consumer method:

    static void Consumer(int i)
    {
        Console.WriteLine(i);
    }
    

    And finally, link it all together and start it up:

    var delayBlock = CreateDelayBlock<int>(TimeSpan.FromMilliseconds(500));
    
    var consumerBlock = new ActionBlock<int>(
        (Action<int>)Consumer,
        new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = DataflowBlockOptions.Unbounded });
    
    delayBlock.LinkTo(consumerBlock, new DataflowLinkOptions { PropagateCompletion = true });
    
    Task.WaitAll(Producer(delayBlock), consumerBlock.Completion);
    

    Here, delayBlock will accept at most one item every 500 ms and the Consumer() method can run multiple times in parallel. To finish processing, call delayBlock.Complete().

    If you want to add some caching per your #2, you could create another TransformBlock do the work there and link it to the other blocks.

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

Sidebar

Related Questions

I have requirement of specifying web part connections in onet.xml. So when site is
In our project we have requirement that, after receiving sms message from third party
I have an MVC2 web application that needs to record the number of unique
I have a web application with a simple file upload requirement (max 1 mb).
I am a bit confused: We have a chat application that has a requirement
We have a process that needs to fire when a change occurs to a
I am writing a webpage for online quiz. The basic requirement I have is
I have requirement where I have to use RED 5 media server for voice
I have requirement to plot Fundamental Score and Technical Score for each ticker across
I have requirement to keep datagridcell always in edit mode. I dont find any

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.