I am not sure how lock works.
What happens if I have a List<T> list
and 2 threads ?
What happens if thread1 start running first and enumerate that list
foreach(T t in list)
{
// code
}
and in the same time, but after thread1 has started, thread2 will lock the list
lock(list)
{
// code
}
I use ThreadPool
do to some processing and I need to know how lock really works and if is thread safe
ThreadPool.QueueUserWorkItem(new WaitCallback(method), obj);