Hey, i need a way in C# to do a really long Enumeration without Deadlocking the program, at the moment i have a List which it enumerates through doing GetEnumerator() on it and using While(e.MoveNext) etc. But it deadlocks i also have it locking the same list when it needs to add stuff to it.
How can i write a thread-safe enumerator without causing locking?
Loading
Sam HobbsPosted Oct 9, 2010, 9:16 PM
Matthew SouthallPosted Oct 9, 2010, 8:55 PM
It seems to deadlock at random times too could be minutes or hours. I don't know c# that well and certainly don't know enumerating well but i can't find any way to get it to work properly with locking at a certain time.
What other information do you need? let me know if any.
Sam HobbsPosted Oct 9, 2010, 8:50 PM
What do you mean by deadlock? What is causing it? Do you need for the list to be accessed by multiple threads? What kind of access? Do you need to be able to add to the list while a different thread is enumerating? If so, then you must decide what to do in that situation.
Without answers to those questions, it seems obvious to me that you simply want to prevent a thread from using the list when anoher thread is using it. If that is not possible then you must explain what your requirements are that make it not a reasonalbe solution.