public static void RunSyncOrAsyncWithLock(object lockObject, Action action, Action whenComplete = null) { if (Monitor.TryEnter(lockObject)) { try { action(); } finally { Monitor.Exit(lockObject); } whenComplete?.Invoke(); } else { MvxAsyncDispatcher.BeginAsync(() => { lock (lockObject) { action(); } whenComplete?.Invoke(); }); } }
public static void RunAsyncWithLock(object lockObject, Action action) { MvxAsyncDispatcher.BeginAsync(() => { lock (lockObject) { action(); } }); }