Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6614955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:24:09+00:00 2026-05-25T20:24:09+00:00

I had 1 collection which I was saving the content to a persistent storage.

  • 0

I had 1 collection which I was saving the content to a persistent storage. Then I ended up having 3 collections which i like to save to a persistent storage.

At first I was using a ThreadPool to save one collection, but now I have 3 collections.Since each collection goes to a different storage, I dont want to combine them or save to same place.

My question is should i use manual Threads and create one thread for each Save() method or should I create 3 thread pool for each method, or should i call all the 3 methods in one ThreadPool.QueueUserWorkItem call.

1.First Approach

ThreadPool.QueueUserWorkItem(o => 
             { Save<Foo>(ConcurrentCollectionStorage.Bus1);
               Save<Bar>(ConcurrentCollectionStorage.Bus2);
               Save<Car>(ConcurrentCollectionStorage.Bus3);
             });

2. Second Approach

ThreadPool.QueueUserWorkItem(o =>
               { Save<Foo>ConcurrentCollectionStorage.Bus); });  
ThreadPool.QueueUserWorkItem(o =>
               { Save<Bar>(ConcurrentCollectionStorage.Bus2); });  
ThreadPool.QueueUserWorkItem(o =>
               { Save<Car>(ConcurrentCollectionStorage.Bus3); });  

3. Third Approach. Creating Thread Manually and join them.

While doing these operations I dont want my application to hang. I want it to process and save the data, and complete, but not to affect the foreground processes, the whole application.

What s the best way to do this?

Which one should I use? Is there a better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:24:09+00:00Added an answer on May 25, 2026 at 8:24 pm

    With .NET 4.0 you can use the Task Parallel Library:

        Task.Factory.StartNew(() => { Save<Foo>(ConcurrentCollectionStorage.Bus1); });
        Task.Factory.StartNew(() => { Save<Bar>(ConcurrentCollectionStorage.Bus2); });
        Task.Factory.StartNew(() => { Save<Car>(ConcurrentCollectionStorage.Bus3); });
    

    However, it isn’t clear from your question what the critical bottleneck is. The TPL can’t help you if you’re bottleneck is Disk IO or network latency.

    If you want your main thread to wait for them all to complete, you can do this (there are several ways to do it):

        Task t1 = Task.Factory.StartNew(() => { Save<Foo>(ConcurrentCollectionStorage.Bus1); });
        Task t2 = Task.Factory.StartNew(() => { Save<Bar>(ConcurrentCollectionStorage.Bus2); });
        Task t3 = Task.Factory.StartNew(() => { Save<Car>(ConcurrentCollectionStorage.Bus3); });
    
        Task.WaitAll(t1,t2,t3);
    

    This way the thread running the tasks will wait until they finish. t1,t2, and t3 will be running asynchronously.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: C# Sortable collection which allows duplicate keys Basically I'd like to make
I have a form which fills some objects of a Collection. I had the
I had en idea, which shortly explained was that i would like to load
I had a little discussion with a friend about the usage of collections in
Has anyone had any luck rolling a custom GWT jar for Google Collections /
Previously, I had a class that wrapped an internal System.Collections.Generic.List<Item> (where Item is a
I had set up a bunch of NUnit unit tests using the Test connection
I had someting like this in my code (.Net 2.0, MS SQL) SqlConnection connection
I was implementing linear search for search in a collection then i thought why
I've got a simple ListView which pulls data from an ObservableCollection and I'm using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.