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