.NET Fiddle

CSharp · Console

/Program.cs

using System;
using System.Collections.Concurrent;
using System.Threading;

public class Program
{
    public static void Main()
    {
        ConcurrentBag<int> bag = new();
        for (int i = 1; i <= 5; i++) bag.Add(i);
        Thread t = new(_ => { for (int i = 6; i <= 10; i++) bag.Add(i); });
        t.Start();
        t.Join();
        Console.WriteLine($"Contents: {String.Join(", ", bag)}");
        Console.Write("Consumed: ");
        while (bag.TryTake(out int item)) Console.Write($"{item}, ");
    }
}
;