Object synchronization method was called from an unsynchronized block of code.
转 http://msdn2.microsoft.com/en-us/library/hf5de04k(VS.71).aspx
如果x是对象就不会报错
如果x是对象就不会报错
object x = new object();
// The next line creates a generic object containing the value of
// x each time the code is executed, so that Enter never blocks.
Monitor.Enter(x);
try {
// Code that needs to be protected by the monitor.
}
finally {
// Always use Finally to ensure that you exit the Monitor.
// The following line creates another object containing
// the value of x, and throws SynchronizationLockException
// because the two objects do not match.
Monitor.Exit(x);
}
// The next line creates a generic object containing the value of
// x each time the code is executed, so that Enter never blocks.
Monitor.Enter(x);
try {
// Code that needs to be protected by the monitor.
}
finally {
// Always use Finally to ensure that you exit the Monitor.
// The following line creates another object containing
// the value of x, and throws SynchronizationLockException
// because the two objects do not match.
Monitor.Exit(x);
}
浙公网安备 33010602011771号