Task Parallel Library - Custom Task Schedulers

后端 未结 4 597
萌比男神i
萌比男神i 2021-02-06 12:35

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 questi

4条回答
  •  执笔经年
    2021-02-06 13:23

    Honestly I would work at a higher level of abstraction and use the TPL Dataflow API for this. The only catch is you would need to write a custom block that will throttle the requests at the rate at which you need because, by default, blocks are "greedy" and will just process as fast as possible. The implementation would be something like this:

    1. Start with a BufferBlock which is the logical block that you would post to.
    2. Link the BufferBlock to a custom block which has the knowledge of requests/sec and throttling logic.
    3. Link the custom block from 2 to to your ActionBlock.

    I don't have the time to write the custom block for #2 right this second, but I will check back later and try to fill in an implementation for you if you haven't already figured it out.

提交回复
热议问题