timotech
Member
- Joined
- Aug 15, 2022
- Messages
- 12
- Programming Experience
- 10+
Hi guys,
Based on my last thread: Await blocking other consumers in a for loop
In which @Skydiver recommend getting more knowledge in concurrency in c#, well I've been able to resolve most of the issues i have, but I have one that is troubling me.
I have multiple producers and they are working fine. I'm using one consumer to get data from the producers.
The challenge I have is that when I use the code below, the program hangs
but when I use only one item e.g producer[0], I get responses, but responses from only one producer
Could it be that i'm implementing the design wrongly or my quad core processor cannot handle it?.
The producers are BlockingCollection<AudioSamples> i.e realtimeSources, 8 in number
Please advice.
Thanks
Based on my last thread: Await blocking other consumers in a for loop
In which @Skydiver recommend getting more knowledge in concurrency in c#, well I've been able to resolve most of the issues i have, but I have one that is troubling me.
I have multiple producers and they are working fine. I'm using one consumer to get data from the producers.
The challenge I have is that when I use the code below, the program hangs
C#:
//multiple producers
for (int i = 0; i < pages.Count; i++)
{
realtimeSources[i] = new BlockingCollection<AudioSamples>();
//producers
Listener listener = new(cbBoxes[i].SelectedIndex, sampleRate, realtimeSources[i]);
listeners.Add(listener);
}
//consumer
BlockingCollection<AudioSamples> audioSamples = new BlockingCollection<AudioSamples>();
_ = BlockingCollection<AudioSamples>.TryTakeFromAny(realtimeSources, out AudioSamples item);
audioSamples.Add(item);
_ = GetBestMatchForStream(realtimeSources[0], modelService, tokenSource.Token, "Wazobia");
but when I use only one item e.g producer[0], I get responses, but responses from only one producer
C#:
//multiple producers
for (int i = 0; i < pages.Count; i++)
{
realtimeSources[i] = new BlockingCollection<AudioSamples>();
//producers
Listener listener = new(cbBoxes[i].SelectedIndex, sampleRate, realtimeSources[i]);
listeners.Add(listener);
}
//consumer (consuming only one producer realtimeSources[0])
_ = GetBestMatchForStream(realtimeSources[0], modelService, tokenSource.Token, "Wazobia");
Could it be that i'm implementing the design wrongly or my quad core processor cannot handle it?.
The producers are BlockingCollection<AudioSamples> i.e realtimeSources, 8 in number
Please advice.
Thanks