在并行执行中的同一线程上执行操作 [英] Perform an operation on same thread within a Parallel Execution
问题描述
我有一个要求,这样我需要在并行执行流程中进行一些同步处理。
我在Parallel foreach中有一些任务。现在我需要做的是,在两者之间进行一些数据库更新。我不想使用async和await完成,因为这会调用多个线程并加载我的服务器。
因为这些数据库更新对我很重要,但是我不希望它们阻止我的主要执行流程。我想要实现的是数据库更新应该始终在同一个线程上同步完成,这将加快主流程。
这是可能的,当我使用任务?如果是这样,任何人都可以建议。
I have a requirement, such that I need to do some synchronous processing within a parallel execution flow.
I have some tasks working within a Parallel foreach. Now what I need to do is that, in between do some database updates. Which I do not want to be done using async and await, since this would invoke multiple threads and loading my server.
Since these database updates are important for me, but I do not want them to block my main flow of execution. What I want to achieve is that the database updates should always be done on the same thread synchronously, which would fasten the main flow.
Is this possible while I use a Task? If so, can anyone please suggest on the same.
推荐答案
这篇关于在并行执行中的同一线程上执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!