Thread queues for dummies

后端 未结 8 1680
终归单人心
终归单人心 2021-02-06 11:59

I have what I assume is a pretty common threading scenario:

  • I have 100 identical jobs to complete
  • All jobs are independent of each other
  • I want t
8条回答
  •  南旧
    南旧 (楼主)
    2021-02-06 12:10

    Microsoft's Reactive Framework is superb for this:

    Action[] jobs = new Action[100];
    
    var subscription =
        jobs
            .ToObservable()
            .Select(job => Observable.Start(job))
            .Merge(15)
            .Subscribe(
                x => Console.WriteLine("Job Done."),
                () => Console.WriteLine("All Jobs Done."))
    

    Done.

    Just NuGet "System.Reactive".

提交回复
热议问题