Can two or more threads iterate over the same List<t> without any problems?
Posted
by CodingCrapper
on Stack Overflow
See other posts from Stack Overflow
or by CodingCrapper
Published on 2010-04-14T13:11:52Z
Indexed on
2010/04/14
13:23 UTC
Read the original article
Hit count: 148
c#
|multithreading
Talking about System.Collections.Generic.List here.
With example below can Method1 and Method2 execute and the same time, on different threads without any problems?
Thanks
class Test
{
private readonly List<MyData> _data;
public Test()
{
_data = LoadData();
}
private List<MyData> LoadData()
{
//Get data from dv.
}
public void Method1()
{
foreach (var list in _data)
{
//do something
}
}
public void Method2()
{
foreach (var list in _data)
{
//do something
}
}
}
© Stack Overflow or respective owner