コード例 #1
0
        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();
                    }
                });
            }
        }
コード例 #2
0
 public static void RunAsyncWithLock(object lockObject, Action action)
 {
     MvxAsyncDispatcher.BeginAsync(() =>
     {
         lock (lockObject)
         {
             action();
         }
     });
 }