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

  • Home
  • SEARCH
  • 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 3999154
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:37:13+00:00 2026-05-20T07:37:13+00:00

I have a main thread which should process data coming from several worker threads.

  • 0

I have a main thread which should process data coming from several worker threads.

But this data is not a specific class.

There are around 6-7 classes, and I need to pass one of this class to the main thread from worker threads.

Previously I had only one class which was passed across threads. I was using;

BlockingCollection<MyClass> mainQueu = new BlockingCollection<MyClass>(new ConcurrentQueue<MyClass>());

So I was pushing MyClass instances from several threads to mainQueu and main thread was trying to take from the mainQueu.

But what if I have more than one classes. Which way is better?

  1. Having a queue for each type of class:

    Of course there should be another queue of type maybe enum, specifying which class is pushed to the queue. And main thread always tries to take from this queue. As soon as any item comes, it will takes from related queue.

  2. Casting:

    Having only one main queue, and in mainQueue class, I can have object member.
    And enum which specifies type of object member.
    And I can convert class to object when pushing to queue, and than in main thread I can cast it back to original class.

Hope it is clear.

Many thanks,regards

  • 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-20T07:37:14+00:00Added an answer on May 20, 2026 at 7:37 am

    A useful trick here is to just have the worker as a queue of delegates; for example, Action. Then the caller can enqueue the appropriate method and (via captured varialbes) any necessary state.

    Say, for example, you have a void Enqueue(Action) method; the caller could do:

    queue.Enqueue(targetObject.Method);
    

    (where targetObject.Method is a void Method() {...}), or can do something like:

    queue.Enqueue(() => SomeMethod(foo, bar, 123));
    

    (where foo and bar are local to the code that wants the work done)

    so we’ve passed lots of state at once, and not once had to think about types – just operations.

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

Sidebar

Related Questions

In my application I have two threads a main thread which is busy most
I have a main window (#1) on my webpage from which I open a
I have a main canvas 'blackboard' in a panel, this canvas has itself several
I have a main table that I must get data from. I have a
I have my main GUI thread, and a second thread running inside it's own
My Goal I would like to have a main processing thread (non GUI), and
i have a table called category in which i have main category ids and
I have a main asp.net app, which is written in asp.net 1.1. Runnning underneath
I have a worker thread that is listening to a TCP socket for incoming
I have a process in a website (Asp.net 3.5 using Linq-to-Sql for data access)

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.