Async Queue Processing With Reactive Extensions

后端 未结 2 996
别那么骄傲
别那么骄傲 2021-02-09 07:27

There are a couple of articles on this, and I have this working...but I want to know how to set a max number of Task threads for my Observable subscriptions at once.

I h

2条回答
  •  忘了有多久
    2021-02-09 08:05

    This is not a function of the Observable, but a function of the Scheduler. The Observable defines what and the scheduler defines where.

    You'd need to pass in a custom scheduler. A simple way to do this would be to subclass TaskScheduler and override the "MaximumConcurrencyLevel" property.

    http://msdn.microsoft.com/en-us/library/system.threading.tasks.taskscheduler.maximumconcurrencylevel.aspx

    I actually found a sample of this on MSDN:

    http://msdn.microsoft.com/en-us/library/ee789351.aspx

    Edit: You asked about how to go from TaskScheduler to IScheduler. Another developer just gave me that little bit of info:

    var ischedulerForRx = new TaskPoolScheduler
    (
        new TaskFactory
        (
            //This is your custom scheduler
            new LimitedConcurrencyLevelTaskScheduler(1)
        )
    );
    

提交回复
热议问题