コード例 #1
0
        public static void TestThatAllThreadsRunInParallel(IThreadManager manager, int depth = 0)
        {
            var results = new List <Task <int> >();

            for (int i = 0; i < 3; i++)
            {
                results.Add(manager.Invoke(slowAction, depth));
            }
            manager.Invoke(() => 1, 1).Wait();

            foreach (var result in results)
            {
                Assert.IsFalse(result.IsCompleted, "The tasks shouldn't have finished yet");
            }
        }
コード例 #2
0
        public static void TestThatThreadsRunInSequence(IThreadManager manager, int depth = 1)
        {
            var results = new List <Task <int> >();

            for (int i = 0; i < 3; i++)
            {
                results.Add(manager.Invoke(slowAction, depth));
            }
            manager.Invoke(() => 1, 1).Wait();

            foreach (var result in results)
            {
                Assert.IsTrue(result.IsCompleted, "All tasks should have finished");
            }
        }
コード例 #3
0
        public virtual void UpdateRootPage(NavigationPage page)
        {
            if (_rootPage != null)
            {
                _rootPage.Pushed       -= OnPushed;
                _rootPage.Popped       -= OnPopped;
                _rootPage.PoppedToRoot -= OnPopped;
            }
            if (page != null)
            {
                page.Pushed       += OnPushed;
                page.Popped       += OnPopped;
                page.PoppedToRoot += OnPopped;
            }
            _rootPage = page;

            var currentPage = CurrentContent as Page ?? page;

            if (currentPage != null)
            {
                var context = currentPage.DataContext();
                if (context != null)
                {
                    currentPage.SetNavigationParameter(NavigationProvider.GenerateNavigationParameter(context.GetType(), string.Empty));
                }
                _threadManager.Invoke(ExecutionMode.AsynchronousOnUiThread, this, currentPage,
                                      (service, p) => service.RaiseNavigated(p, p.GetNavigationParameter() as string, NavigationMode.New),
                                      OperationPriority.Low);
            }
        }
コード例 #4
0
 public void Close()
 {
     if (_delayTimer != null)
     {
         _delayTimer.Dispose();
     }
     if (_showTimer != null)
     {
         _showTimer.Dispose();
     }
     if (_toast == null)
     {
         return;
     }
     _threadManager.Invoke(ExecutionMode.SynchronousOnUiThread, this, this, (w, wrapper) =>
     {
         Toast toast = w._toast;
         if (toast != null)
         {
             w._toast = null;
             toast.Cancel();
             w._tcs.TrySetResult(null);
         }
     }, OperationPriority.High);
 }
コード例 #5
0
 protected virtual void OnPropertyChanged(PropertyChangedEventArgs args, ExecutionMode executionMode)
 {
     Should.NotBeNull(args, nameof(args));
     if (IsNotificationsSuspended)
     {
         IsNotificationsDirty = true;
     }
     else
     {
         ThreadManager.Invoke(executionMode, this, args, RaisePropertyChangedDelegate);
     }
 }
コード例 #6
0
 private void TryCloseViewModel(IViewModel viewModel, object parameter)
 {
     _threadManager.Invoke(ExecutionMode.AsynchronousOnUiThread, this, viewModel, parameter, (provider, vm, p) =>
     {
         if (ReferenceEquals(provider._closingViewModel, vm))
         {
             return;
         }
         try
         {
             provider._closedFromViewModel = true;
             if (provider.NavigationService.TryClose(vm, p as IDataContext))
             {
                 provider.OnViewModelClosed(vm, p, true);
             }
         }
         finally
         {
             provider._closedFromViewModel = false;
         }
     });
 }
コード例 #7
0
 private void CloseableViewModelOnClosed(ICloseableViewModel sender, ViewModelClosedEventArgs e)
 {
     _threadManager.Invoke(ExecutionMode.AsynchronousOnUiThread, this, NavigationService, e,
                           (provider, service, args) =>
     {
         if (ReferenceEquals(provider._closingViewModel, args.ViewModel))
         {
             return;
         }
         try
         {
             provider._closedFromViewModel = true;
             if (service.TryClose(args.ViewModel, args.Parameter as IDataContext))
             {
                 OnViewModelClosed(args.ViewModel, args.Parameter, provider, true);
             }
         }
         finally
         {
             provider._closedFromViewModel = false;
         }
     });
 }
コード例 #8
0
        public SearchResult EvaluateChildren(IProbabilisticState startState, SearchContext searchContext)
        {
            var neighbors = startState.GetNeighbors().ToArray();

            if (!neighbors.Any())
            {
                var evaluation = startState.Evaluate(searchContext.CurrentDepth, searchContext.StatesUpTillNow, searchOptions);
                return(new SearchResult(evaluation, startState));
            }

            var storedStates = new ConcurrentDictionary <IState, double>();
            var results      = new List <Tuple <double, Task <SearchResult> > >();

            foreach (var neighbor in neighbors)
            {
                var wrappedState = new ProbablisticStateWrapper(neighbor.Item2, startState);
                var searchResult = threadManager.Invoke(() =>
                                                        deterministicSearchUtils.EvaluateChildren(wrappedState, searchContext.CloneWithMaxAlphaAndBeta(), storedStates), searchContext.CurrentDepth);
                results.Add(new Tuple <double, Task <SearchResult> >(neighbor.Item1, searchResult));
            }

            return(Reduce(results, startState));
        }