public void Handle(Input.StartCancellableWorkTrigger input)
 {
     AsyncInputHandlers.Run(async() => {
         WorkCancellationTokenSource?.Cancel();
         WorkCancellationTokenSource = new CancellationTokenSource();
         var cts = WorkCancellationTokenSource;
         IProgress <int> progress = new Progress <int>(i => WorkProgress = i.ToString());
         try
         {
             await Task.Run(async() => {
                 for (int i = 1; i <= 100; i++)
                 {
                     // if we referenced the WorkCancellationTokenSource field directly, we would have a race condition between
                     // background and scheduler (UI) threads
                     await Task.Delay(TimeSpan.FromMilliseconds(100), cts.Token);
                     progress.Report(i);
                 }
             },
                            cts.Token);
         }
         catch (TaskCanceledException)
         {
             WorkProgress += " (Canceled)";
         }
     });
 }
 public void Handle(Input.StartSimpleWorkTrigger input)
 {
     AsyncInputHandlers.Run(async() => {
         WorkProgress = "Started";
         await Task.Delay(TimeSpan.FromSeconds(1));
         WorkProgress = "Done";
     });
 }
Esempio n. 3
0
 // IsHovered is set on the client side. Every time a person gets hovered, isHovered is set to 1.
 // And the value is set to 0 on blur.
 public void Handle(Input.IsHovered action)
 {
     if (!this.DataIsLoaded && action.Value != 0)
     {
         Random rnd = new Random();
         AsyncInputHandlers.Run(() => StartDataRetrieval(rnd.Next(minDataRetrievalDelay, maxDataRetrievalDelay)));
     }
 }
 public void Handle(Input.ShowMessageTrigger action)
 {
     AsyncInputHandlers.Run(async() => {
         this.ServerMessage = "This Message was set on the Server side!";
         await Task.Delay(TimeSpan.FromSeconds(3));
         this.ServerMessage = null;
     });
 }
        private void Handle(Input.StartProgressTrigger action)
        {
            if (this.TaskIsRunnning)
            {
                return;
            }

            AsyncInputHandlers.Run(StartSimpleProgressBarAsync);
        }
 public void Handle(Input.StartProgressWorkTrigger input)
 {
     AsyncInputHandlers.Run(async() => {
         IProgress <int> progress = new Progress <int>(i => WorkProgress = i.ToString());
         await Task.Run(async() => {
             for (int i = 1; i <= 30; i++)
             {
                 await Task.Delay(TimeSpan.FromMilliseconds(100));
                 progress.Report(i);
             }
         });
     });
 }
 public void Handle(Input.StartFaultyWorkTrigger input)
 {
     AsyncInputHandlers.Run(async() => {
         IProgress <int> progress = new Progress <int>(i => WorkProgress = i.ToString());
         try
         {
             await Task.Run(async() => await FaultyJob(progress));
         }
         catch (Exception e)
         {
             WorkProgress += $" (error caught in the UI thread: {e.Message})";
         }
     });
 }