Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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.
Posted
Comments
Rob Philpott 29-Jul-14 12:22pm    
Don't get it. You want synchronous behavior, yet want to use asynchronous processing?
ankurtrue1 29-Jul-14 13:35pm    
The whole process is running in parallel and asynchronous fashion. However within the individual threads.I will be updating database in multiple threads as well. But the point is, that there is one separate process which I need to do for say "Health Monitoring" where I need to update values in database, which should not hamper/affect the main flow of the code. Hope its clear now?
Sergey Alexandrovich Kryukov 29-Jul-14 20:53pm    
Agree with Rob. It does not seem to make any sense. TPL is based in threading...
—SA
ankurtrue1 30-Jul-14 3:15am    
Yes, Its correct and I also agree. But since the "status updates" is kind of monitoring mechanism. Hence the architect has asked to make it work this way, so that main flow is not delayed due to multiple threads catering to this task.
gggustafson 1-Aug-14 11:09am    
You are going to need some form of lock to insure that one of your threads does not interfere with the other thread.

Also, concerns regarding "loading a server" are best left for after implementation. I'll bet you will find no problems and that you are scaring yourself needlessly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900