Exemplo n.º 1
0
 private async void SetVersionText()
 {
     await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         ToasterVersionText.Text = toasterServer.Service.ToasterVersion.ToString();
     });
 }
        // PlayNextImage
        // Called when a new image is displayed due to a timeout.
        // Removes the current image object and queues a new next image.
        // Sets the next image index as the new current image, and increases the size
        // of the new current image. Then sets the timeout to display the next image.

        private async void PlayNextImage(int num)
        {
            // Stop the timer to avoid repeating.
            if (timer != null)
            {
                timer.Stop();
            }

            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                      async() =>
            {
                SlideShowPanel.Children.Remove((UIElement)(SlideShowPanel.FindName("image" + num)));
                var i = await QueueImage(num + 2, false);

                currentImage = num + 1;
                ((Image)SlideShowPanel.FindName("image" + currentImage)).Width = imageSize;
            });

            timer          = new Windows.UI.Xaml.DispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, timeLapse);
            timer.Tick    += delegate(object sender, object e)
            {
                PlayNextImage(num + 1);
            };
            timer.Start();
        }
Exemplo n.º 3
0
 async private void Http_PercentDone(object sender, Chilkat.PercentDoneEventArgs eventArgs)
 {
     await m_dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         //textBox2.Text = eventArgs.PercentDone.ToString();
         progressBar1.Value = eventArgs.PercentDone;
     });
 }
Exemplo n.º 4
0
 async void Output(string content)
 {
     await _dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         content.PrintDebug();
         //ResultText.Text = content;
     });
 }
Exemplo n.º 5
0
 private async void ProximityDeviceArrived(object sender)
 {
     await _dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                () =>
     {
         MessageTextBlock.Text += "Proximate device arrived.\n";
     });
 }
Exemplo n.º 6
0
 private async void XboxLiveUser_SignOutCompleted(object sender, SignOutCompletedEventArgs args)
 {
     await UIDispatcher.RunAsync(
         Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         m_xboxliveContexts.Remove(args.User.WindowsSystemUser.NonRoamableId);
         UserInfoLabel.Text = "User signed out";
         Log("User " + args.User.Gamertag + " signed out.");
         m_socialManagerUI.RemoveUser(args.User);
     });
 }
 async void watcher_Added(DeviceWatcher sender, DeviceInformation deviceInterface)
 {
     interfaces[count] = deviceInterface;
     count            += 1;
     if (isEnumerationComplete)
     {
         await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
         {
             DisplayDeviceInterfaceArray();
         });
     }
 }
        async void TranscodeComplete()
        {
            OutputText("Transcode completed.");
            OutputPathText("Output (" + _OutputFile.Path + ")");
            Windows.Storage.Streams.IRandomAccessStream stream = await _OutputFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

            await _dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                OutputVideo.SetSource(stream, _OutputFile.ContentType);
            });

            EnableButtons();
            SetCancelButton(false);
        }
Exemplo n.º 9
0
        // </SnippetStartAndStop>

        // <SnippetReceiverEvents>
        // <SnippetCurrentTimeChangeRequested>
        async void receiver_CurrentTimeChangeRequested(
            Windows.Media.PlayTo.PlayToReceiver sender,
            Windows.Media.PlayTo.CurrentTimeChangeRequestedEventArgs args)
        {
            await dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                VideoPlayer.Position = args.Time;
                receiver.NotifySeeking();
                seeking = true;
            });
        }
Exemplo n.º 10
0
        public async void MainLoop()
        {
            await appDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                while (true)
                {
                    //Increment ticks
                    ++ticks;

                    //calculate frame delta to prevent more than 60 frames from occuring every second
                    TimeSpan timeDelta = DateTime.Now - lastFrameTime;
                    delta = timeDelta.TotalMilliseconds;

                    if (delta >= 1000.0 / 60.0)
                    {
                        //Run update function
                        Update();

                        //Reset last frame time
                        lastFrameTime = DateTime.Now;
                    }
                    //Process any UI events if needed
                    else if (appDispatcher.ShouldYield())
                    {
                        appDispatcher.ProcessEvents(Windows.UI.Core.CoreProcessEventsOption.ProcessAllIfPresent);
                    }
                    //Wait 4ms if nothing needs to happen
                    else
                    {
                        Task.Delay(4).Wait();
                    }
                }
            });
        }
Exemplo n.º 11
0
        public async Task <ObservableCollection <Result> > GetSearchResultsAsync(string search)
        {
            ObservableCollection <Result> Items = null;

            if (cache.ContainsKey(CallerName() + search))
            {
                Items = cache[CallerName() + search] as ObservableCollection <Result>;
            }
            else
            {
                Items = new ObservableCollection <Result>((await ImageRepository.Instance.GetResultsAsync(search) as RootObject).responseData.results);
                Task.Factory.StartNew(async() =>
                {
                    int calls = 10;
                    for (int i = 1; i < calls; i++)
                    {
                        ObservableCollection <Result> moreItems = new ObservableCollection <Result>((await ImageRepository.Instance.GetResultsAsync(search, i * 8) as RootObject).responseData.results);
                        UIDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
                        {
                            Items.AddRange(moreItems);
                        });
                    }
                });
                cache.Add(CallerName() + search, Items);
            }
            return(Items);
        }
Exemplo n.º 12
0
        public static async Task MakeLikeAsync(ICanChangeLikModel model, Windows.UI.Core.CoreDispatcher dispatcher, SymbolIcon like, SymbolIcon coloredLike)
        {
            if (model == null)
            {
                return;
            }

            bool isReply = model is FeedReplyModel;
            var  u       = UriProvider.GetUri(
                model.Liked ? UriType.OperateUnlike : UriType.OperateLike,
                isReply ? "Reply" : string.Empty, model.Id);
            var o = (JObject) await GetDataAsync(u, true);

            await dispatcher?.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                model.Liked = !model.Liked;
                if (isReply)
                {
                    model.Likenum = o.ToString().Replace("\"", string.Empty);
                }
                else if (o != null)
                {
                    model.Likenum = $"{o.Value<int>("count")}";
                }

                if (like != null)
                {
                    like.Visibility = model.Liked ? Visibility.Visible : Visibility.Collapsed;
                }
                if (coloredLike != null)
                {
                    coloredLike.Visibility = model.Liked ? Visibility.Collapsed : Visibility.Visible;
                }
            });
        }
Exemplo n.º 13
0
        private async void ToasterFinder_ToasterFound(object sender, ToasterFoundEventArgs args)
        {
            toasterClient = new ToasterClient(args.Consumer);

            toasterClient.Consumer.DarknessLevelChanged       += Consumer_DarknessLevelChanged;
            toasterClient.Consumer.Signals.ToastBurntReceived += Signals_ToastBurntReceived;

            string versionText = toasterClient.ToasterVersion.ToString();

            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                EnableUI(versionText);
            });

            UpdateSliderValue();
        }
Exemplo n.º 14
0
        async void LangtonsLoops_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(LangtonsLoops.Lives))
            {
                _stepCount++;

                if (_isUpdating)
                {
                    return;
                }

                _isUpdating = true;

                await _thisDispatcher.RunAsync(
                    Windows.UI.Core.CoreDispatcherPriority.Normal,
                    () =>
                {
                    UpdateBitmap(_langtonsLoops.Lives);

                    _drawCount++;
                    TimeSpan duration       = DateTimeOffset.Now.Subtract(_startTime);
                    this.textCycleTime.Text = string.Format("{0:0.0000}秒", duration.TotalMilliseconds / _stepCount / 1000.0);
                    int drawRate            = (int)(_drawCount * 100.0 / _stepCount);
                    this.textDrawRate.Text  = string.Format("{0}% ({1}/{2})", drawRate, _drawCount, _stepCount);
                }
                    );

                _isUpdating = false;
            }
        }
Exemplo n.º 15
0
        async private void WriteMessageText(string message, bool overwrite = false)
        {
            await messageDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                             () =>

            {
                if (overwrite)
                {
                    textBlock.Text = message;
                }

                else
                {
                    textBlock.Text += message;
                }
            });
        }
Exemplo n.º 16
0
 private async void NotifyPropertyChangedAsync(string prop)
 {
     if (dispatcher != null)
     {
         await dispatcher.RunAsync(
             Windows.UI.Core.CoreDispatcherPriority.Normal,
             () => PropertyChanged(this, new PropertyChangedEventArgs(prop)));
     }
 }
Exemplo n.º 17
0
 public void OnPropertyChanged(string propertyName)
 {
     if (PropertyChanged != null)
     {
         _dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
         {
             PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
         });
     }
 }
Exemplo n.º 18
0
 private async void LoadFromWeb()
 {
     await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
     {
         ObservableCollection <HotDataItem> tmp = await DataService.Instance.LoadHotItemsList();
         if (tmp.Count() > 0)
         {
             HotItemsList = tmp;
         }
     });
 }
Exemplo n.º 19
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///  Send this message.
 /// </summary>
 /// <param name="action">
 ///  The action.
 /// </param>
 ///-------------------------------------------------------------------------------------------------
 public async Task Send(Action action)
 {
     if (_dispatcher == null)
     {
         action();
         await Hyperstore.Modeling.Utils.CompletedTask.Default;
     }
     else
     {
         await _dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(action));
     }
 }
Exemplo n.º 20
0
 private async void LoadFromWeb()
 {
     await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
     {
         ObservableCollection <CollectionDataItem> tmp = await DataService.Instance.LoadCollection();
         if (tmp.Count() > 0)
         {
             Collection = tmp;
             RepopulateFilteredCollection(); // Required because previous lines do not fire Collection_CollectionChanged
         }
     });
 }
Exemplo n.º 21
0
 /// <summary>
 /// This event handler is invoked when a Bidi response is raised.
 /// </summary>
 private async void OnBidiResponseReceived(object sender, PrinterQueueEventArgs responseArguments)
 {
     // Invoke the ink level event with appropriate data.
     // Dispatching this event invocation to the UI thread is required because in JavaScript,
     // events handlers need to be invoked on the UI thread.
     await dispatcher.RunAsync(
         Windows.UI.Core.CoreDispatcherPriority.Normal,
         () =>
     {
         OnInkLevelReceived(sender, ParseResponse(responseArguments));
     });
 }
Exemplo n.º 22
0
 async void StopWatcher(object sender, RoutedEventArgs eventArgs)
 {
     try
     {
         if (watcher.Status == Windows.Devices.Enumeration.DeviceWatcherStatus.Stopped)
         {
             await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
             {
                 OutputText.Text = "The enumeration is already stopped.";
             });
         }
         else
         {
             watcher.Stop();
         }
     }
     catch (ArgumentException)
     {
         await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
         {
             OutputText.Text = "Caught ArgumentException. Failed to stop watcher.";
         });
     }
     this.btnWatchDevices.IsEnabled = true;
     this.btnStop.IsEnabled         = !(this.btnWatchDevices.IsEnabled);
 }
Exemplo n.º 23
0
        /// <summary>
        /// Returns the app to the OptionsPage.  Clears data and dispatches the app to the UI thread to insure app stability
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void returnHome_Click(object sender, RoutedEventArgs e)
        {
            var currentApp = (App)App.Current;

            currentApp.CurrentRecogResult = null;
            currentApp.CurrentImageRecog  = null;
            Frame.Navigate(typeof(OptionsPage));

            //dispatch app to the UI thread
            Windows.UI.Core.CoreDispatcher dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                      new Windows.UI.Core.DispatchedHandler(
                                          () => Frame.Navigate(typeof(WindowsApp.Views.OptionsPage))));
        }
        async private void HodClient_requestCompletedWithContent(string response)
        {
            await messageDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                indicator.Visibility = Visibility.Collapsed;
                inprogress           = false;
                mediaList            = (QueryTextIndexResponse)parser.ParseCustomResponse <QueryTextIndexResponse>(ref response);
                if (mediaList != null)
                {
                    listViewModel.ClearData();
                    foreach (QueryTextIndexResponse.Document doc in mediaList.documents)
                    {
                        ContentModel item = new ContentModel();
                        item.Type         = doc.mediatype[0];
                        item.Title        = doc.medianame[0];
                        if (doc.filename != null)
                        {
                            item.filename = doc.filename[0];
                        }
                        item.reference = doc.reference;
                        item.index     = doc.index;

                        var type = item.Type.Split('/');
                        if (type[0] == "video")
                        {
                            item.Icon = "Assets/video_icon.png";
                        }
                        else
                        {
                            item.Icon = "Assets/audio_icon.png";
                        }

                        listViewModel.Items.Add(item);
                    }
                }
            });
        }
Exemplo n.º 25
0
        private async void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args)
        {
            if (_device == null)
            {
                var device = await SerialDevice.FromIdAsync(args.Id);

                if (device != null && device.UsbVendorId == 0x0483 && device.UsbProductId == 0x5740)
                {
                    await Dispatcher?.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => SelectSsid(string.Empty, string.Empty));

                    _device = new WiFiScannerDevice(new Devices.UWPDevice(device));
                    _device.DataReceived += _device_DataReceived;
                    _device.ScanNetworks();
                }
            }
        }
Exemplo n.º 26
0
 private void RaiseCurrentItemChanged()
 {
     CurrentItemChanged?.Invoke(this, CurrentItem);
     if (dispatcher == null || dispatcher.HasThreadAccess)
     {
         PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentItem)));
         PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(NextItem)));
     }
     else
     {
         var _ = dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
         {
             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentItem)));
             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(NextItem)));
         });
     }
 }
Exemplo n.º 27
0
        public static async Task MarshallToUiThread(Windows.UI.Core.DispatchedHandler fn)
        {
            if (uiDispatcher == null)
            {
                uiDispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread()?.Dispatcher;
                if (uiDispatcher == null)
                {
                    System.Diagnostics.Debug.WriteLine("Could not get ui dispatcher.");
                    return;
                }
            }

            await uiDispatcher
            .RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal,
                fn);
        }
Exemplo n.º 28
0
 protected async Task InvokeAsync(Action actionToInvoke)
 {
     if (DispatcherToUse != null)
     {
         await DispatcherToUse.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
         {
             actionToInvoke();
         });
     }
     else
     {
         await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
         {
             actionToInvoke();
         });
     }
 }
Exemplo n.º 29
0
        public static async Task MakeLikeAsync(ICanChangeLike like, Windows.UI.Core.CoreDispatcher dispatcher, SymbolIcon like1, SymbolIcon like2)
        {
            if (like == null)
            {
                return;
            }
            bool    isReply = like is FeedReplyModel;
            bool    isLike  = false;
            JObject o;

            if (like.Liked)
            {
                o = (JObject) await GetDataAsync(DataUriType.OperateUnlike, true, isReply? "Reply" : string.Empty, like.Id);
            }
            else
            {
                o = (JObject) await GetDataAsync(DataUriType.OperateLike, true, isReply? "Reply" : string.Empty, like.Id);

                isLike = true;
            }

            await dispatcher?.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                like.Liked = isLike;
                if (isReply)
                {
                    like.Likenum = o.ToString().Replace("\"", string.Empty);
                }
                else if (o != null)
                {
                    like.Likenum = o.Value <int>("count").ToString();
                }

                if (like1 != null)
                {
                    like1.Visibility = isLike ? Visibility.Visible : Visibility.Collapsed;
                }
                if (like1 != null)
                {
                    like2.Visibility = isLike ? Visibility.Collapsed : Visibility.Visible;
                }
            });
        }
Exemplo n.º 30
0
        /// <summary>
        /// Asychronously saves changes in the data service by using the provided <see cref="T:Windows.UI.Core.CoreDispatcher"/>.
        /// </summary>
        /// <param name="context">The <see cref="T:System.Data.Services.Client.DataServiceContext"/> instance on which this extension method is enabled. </param>
        /// <param name="options">The save changes options emuneration, which supports flags.</param>
        /// <param name="dispatcher">The <see cref="T:Windows.UI.Core.CoreDispatcher"/> used to marshal the response back to the UI thread.</param>
        /// <returns>A <see cref="T:System.Threading.Tasks.Task`1"/> that, when completed, returns the result as a <see cref="T:System.Data.Services.Client.DataServiceResponse"/>.</returns>
        public static async Task <DataServiceResponse> SaveChangesAsync(this DataServiceContext context, SaveChangesOptions options, Windows.UI.Core.CoreDispatcher dispatcher)
        {
            var tcs = new TaskCompletionSource <DataServiceResponse>();

            context.BeginSaveChanges(async iar =>
            {
                await dispatcher.RunAsync(
                    Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    try
                    {
                        tcs.SetResult(context.EndSaveChanges(iar));
                    }
                    catch (DataServiceRequestException ex)
                    {
                        throw ex;
                    }
                });
            }, null);
            return(await tcs.Task);
        }