set priority for Parallel.For loop

前端 未结 5 1633
半阙折子戏
半阙折子戏 2021-01-05 16:21

Ok, here\'s the situation: My main/UI thread (call it Thread1) is used for acquiring a batch of images from a phsycial document scanner. When a batch has been acquired, a se

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-05 17:02

    Is there a way to "limit" a Parallel.For loop so that it does not max out my processors?

    Yes, you can add an Options with MaxDegreeOfParallelism=N.

    Or to set the processing priority?

    No. It is a ThreadPool (borrowed) thread. Don't change its properties. Actually it's a bunch of pool threads.

    Or am I misunderstanding how a Parallel.For loop works? Is it blocking Thread1 somehow?

    Yes, from the outside Parallel.For(...) is a blocking call. So run it on a separate Task or Backgroundworker, not from the main thread.

提交回复
热议问题