I had 1 collection in which I saved the contents to persistent storage. Then I got 3 collections that I like to keep them in permanent storage.
At first I used ThreadPool to save one collection, but now I have 3 collections. Since each collection goes to a different repository, I do not want to combine them or keep them in the same place.
My question is whether I should use manual threads and create one thread for each Save () method, or should I create 3 thread pools for each method, or should I call all 3 methods in one call to ThreadPool.QueueUserWorkItem.
1. The first approach
ThreadPool.QueueUserWorkItem(o => { Save<Foo>(ConcurrentCollectionStorage.Bus1); Save<Bar>(ConcurrentCollectionStorage.Bus2); Save<Car>(ConcurrentCollectionStorage.Bus3); });
2. The second approach
ThreadPool.QueueUserWorkItem(o => { Save<Foo>ConcurrentCollectionStorage.Bus); }); ThreadPool.QueueUserWorkItem(o => { Save<Bar>(ConcurrentCollectionStorage.Bus2); }); ThreadPool.QueueUserWorkItem(o => { Save<Car>(ConcurrentCollectionStorage.Bus3); });
3. The third approach. Create a stream manually and join them.
Performing these operations, I do not want my application to freeze. I want it to process and save data and complete, but not affect the foreground processes, the entire application.
What is the best way to do this?
Which should i use? Is there a better way to do this?
source share