private void FaceDetection_FaceDetected(FaceDetectionEffect sender, FaceDetectedEventArgs args) { DispatcherWrapper.Current().Dispatch(() => { var properties = DefaultManager.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties; if (properties == null || properties.Width == 0 || properties.Height == 0) { return; } var canvas = FacesCanvas.Child as Canvas; canvas.Height = properties.Height; canvas.Width = properties.Width; FaceDetected?.Invoke(sender, args); canvas.Children.Clear(); foreach (var face in args.ResultFrame.DetectedFaces.Where(x => x.FaceBox.Width != 0 && x.FaceBox.Height != 0)) { var box = new Rectangle { Height = face.FaceBox.Height, Width = face.FaceBox.Width, Stroke = FacesBoxColor.ToSolidColorBrush(), StrokeThickness = 2, }; Canvas.SetLeft(box, face.FaceBox.X); Canvas.SetTop(box, face.FaceBox.Y); canvas.Children.Add(box); } FaceCountChanged?.Invoke(this, canvas.Children.Count()); }); }
public Task FillItemsAsync() { return(Task.Run(async delegate { var dispatcher = DispatcherWrapper.Current(); //Для потомков //await dispatcher.DispatchAsync(() => items.Clear()); //foreach (var item in Randomizer // .Configure(ItemsRequired, UniqueOnly, SortAfter) // .RollItems() // .Select(x => new ArrayItem(x))) //{ // await dispatcher.DispatchAsync(() => items.Add(item)); //} var items = new ObservableCollection <ArrayItem>(Randomizer.Configure(ItemsRequired, UniqueOnly, SortAfter) .RollItems() .Select(x => new ArrayItem(x))); await dispatcher.DispatchAsync(delegate { ArraySource.Instance.Items = items; }); })); }
public NavButtonBehavior() { if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled) { _dispatcher = DispatcherWrapper.Current(); _throttleHelper = new EventThrottleHelper { Throttle = 1000 }; } }
private static async Task <T> ShowAsync <T>(Func <Task <T> > show, IDispatcherWrapper dispatcher) { lock (DialogState) { while (DialogState.Showing) { Monitor.Wait(DialogState); } DialogState.Showing = true; } dispatcher = dispatcher ?? DispatcherWrapper.Current(); var result = await dispatcher.DispatchAsync(async() => await show()); lock (DialogState) { DialogState.Showing = false; Monitor.PulseAll(DialogState); } return(result); }
public async Task DisplayResults() { var source = _cancellationTokens.AddAndReturn(new CancellationTokenSource()); await Task.Factory.StartNew(() => { _dataService.CuisineType = CuisineType; var restaurants = _dataService.listOfRestaurants().Result; if (!source.Token.IsCancellationRequested) { DispatcherWrapper.Current().Dispatch(() => { Restaurants.Clear(); foreach (var restaurant in restaurants) { Restaurants.Add(restaurant); } }); } }, source.Token); }
//public override async Task OnNavigatedToAsync(object parameter, navigationmode mode, idictionary<string, object> state) //{ // // defaults // price1checked = true; // price2checked = true; // star2checked = true; // star3checked = true; // selectedcuisine = "indian"; // distance = 1; // await searchasync(); //} public async Task SearchAsync() { var source = _cancellationTokens.AddAndReturn(new CancellationTokenSource()); await Task.Factory.StartNew(async() => { // TODO: convert distance number to kilos var restaurants = await _dataService.GetReataurantsAsync(); if (!source.Token.IsCancellationRequested) { DispatcherWrapper.Current().Dispatch(() => { Restaurants.Clear(); foreach (var restaurant in restaurants) { Restaurants.Add(restaurant); } }); } }, source.Token); }