using System.Collections.Concurrent;
var obj = new object();
var test = new ConcurrentBag<UserConnection>
{
new()
{
Name = "John Doe",
IsActive = false
}
};
lock (obj)
{
test.First(x => x.Name == "John Doe").IsActive = true;
}
foreach (var t in test)
{
Console.WriteLine(new { t.Name, t.IsActive });
}
class UserConnection
{
public string Name { get; set; }
public bool IsActive { get; set; }
}
using System.Collections.Concurrent;
var obj = new object();
var test = new ConcurrentBag<UserConnection>
{
new()
{
Name = "John Doe",
IsActive = false
}
};
lock (obj)
{
test.First(x => x.Name == "John Doe").IsActive = true;
}
foreach (var t in test)
{
Console.WriteLine(new { t.Name, t.IsActive });
}
class UserConnection
{
public string Name { get; set; }
public bool IsActive { get; set; }
}