protected static object MObjLock = new object();//同步锁 public string GetData(int mId) { Monitor.Enter(MObjLock);//lock string data = string.Empty; try { //你的代码
} catch (Exception err) { Log4NetHelper.WriteError(err); } finally { Monitor.Exit(MObjLock);//unlock } return data; }
Monitor.Enter(T)上锁后,其它代码调用此方法要等到Monitor.Exit(T)之后,适用于抽奖等