Description
情境: ASP.NET 的網站忽然某一個功能會出現 System.Threading.SynchronizationLockException 其它都是正常. 錯誤訊息: System.Threading.SynchronizationLockException: Object synchronization method was called from an unsynchronized block of code. 測試: 測試發現如果使用MethodImplOptions.Synchronized,若thread進入執行並故意abort掉,可以重現.SynchronizationLockException。 若改用lock則不會發生問題 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Runtime.CompilerServices; using System.Text; using System.Windows.Forms; using System.Threading; namespace LockDemo { public partial class Form1 : Form { public Form1() ...