Comments on: ConcurrentBag in C# https://code-maze.com/csharp-concurrentbag/ Learn. Code. Succeed. Thu, 05 Jan 2023 13:21:04 +0000 hourly 1 https://wordpress.org/?v=6.7.5 By: Marinko Spasojević https://code-maze.com/csharp-concurrentbag/#comment-7288 Thu, 05 Jan 2023 13:21:04 +0000 https://drafts.code-maze.com/?p=78873#comment-7288 In reply to Branislav Petrović.

Hi Branislav.

Well, I didn’t use channels but as much as I know, they are created to provide a way for communication between threads or tasks using async messaging. So the purpose is completely different from the ConcurrentBag where you want to add and remove items in a thread-safe way.

So, in general, you would use ConcurrentBag when you need a thread-safe collection for storing and accessing items concurrently, and you would use Channels when you need to communicate between threads or tasks using asynchronous message-passing.

Again, I know that my answer is a bit wide here, but as I said, I didn’t use channels so I can’t go into details about it.

]]>
By: Branislav Petrović https://code-maze.com/csharp-concurrentbag/#comment-7284 Thu, 05 Jan 2023 11:48:05 +0000 https://drafts.code-maze.com/?p=78873#comment-7284 Great overview of ConcurrentBag class! In which scenarios is better to use ConcurrentBag over Channels and vice versa?

Thanks!

]]>