On the one hand I want to lock some critical section with 'Lock()', but on the other hand I want to let possibility of suspending a thread at some button's click (I know that the 'Suspend' function should not be used, but I really have no choice).
Possibly that other threads will want to enter to this critical section. How can I prevent the DEADLOCK?
If the 'Suspend' function was throwing exception (like the 'Abort()' function), there was no problem. The monitor was released in the 'finally' statement...
For example:
static List<Thread> threadList = new List<Thread>();
public static List<Thread> ThreadList
{
get { lock (_locker) { return SaveLists.threadList; } }
set { lock (_locker) { SaveLists.threadList = value; } }
}
If I'll suspend the thread that locked the object, and after thate an another thread will want to set/get the list =>DEADLOCK.