1

i have 2 threads one adds to a Enqueue and one does the Dequeue and do some processing,

now sometimes the Queue will become empty, and it might couple minutes to fill it with one elment, on the other hand it can have couple hundred elements if the data was local, so it has a mix of local data which is added fast and data that has to be first downloaded.

now if i do something like

While(queue.count > 0)
{  
    //lock denque and process
} 

it would exit the loop and the thread will end, on the other hand if i do something like

While(queue.count > 0 && DownloaderThreadisRunning)
    {  
        //lock denque and process
    } 

i will have another problem since some objects might take processing time to a point where the Enqueue thread has ended its job, so it wont get in the loop.

i thought of something like

While(queue.count > 0)
        {  
            //lock denque and process
         if(!DownloaderThreadisRunning && queue.Count==0)
         {
            break;
         }
        } 

but are thre any built in solutions to manage such things?

1 Answer 1

2

if you can use ConcurrentQueue than you do have lot more abstraction over creating your own Producer and Consumer.

Sign up to request clarification or add additional context in comments.

1 Comment

thats much better also used it with a BlockingCollection, and things are simpler, Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.