public static DangerousExternalLock Lock(object o, Action onUnlockF) { DangerousExternalLock l = new DangerousExternalLock(o) { OnUnlockedF = onUnlockF }; Monitor.Enter(o); return(l); }
/// <summary> /// This function returns an object that holds a lock on the .Mesh for writing. /// You should only call like this: /// /// using (var danger = meshSO.AcquireDangerousMeshLockForEditing(editType)) { /// ...do your thing to meshSO.Mesh /// } /// /// This will safely lock the mesh so that background mesh-read threads are blocked. /// ***DO NOT*** hold onto this lock, or you will never be able to update the mesh again! /// </summary> DangerousExternalLock AcquireDangerousMeshLockForEditing(GeometryEditTypes editType) { return(DangerousExternalLock.Lock(mesh_write_lock, () => { notify_mesh_edited(editType); })); }