Beispiel #1
0
        protected virtual async Task StartAeration()
        {
            lock (aerateLock)
            {
                if (aerating)
                {
                    return;
                }
                aerating = true; // Start flag.
            }

            CrossKeepAwakeService.Instance.StartAwake(); // Start keep awake.
            aerateTimer.Restart();

            // Log run, stop shaking glass, and fade out.
            if (shakeCancelledSource != null)
            {
                shakeCancelledSource.Cancel();
            }
            AnimateOnMain(async() => await glassHereContainer.FadeTo(0, 200));

            int duration = vm.DurationValue * 1000;
            var tES      = EnableStopButton(200);
            var tEM      = EnableMessages(200);
            await Task.WhenAll(tES, tEM);

            if (fluidSim != null)
            {
                fluidSim.LockMotion();
            }
            try
            {
                aerateCancelledSource = new CancellationTokenSource();
                RunVibrationPattern(aerateCancelledSource.Token);
                RunMessagePattern(800, duration, aerateCancelledSource.Token);
                await Task.Delay(duration, aerateCancelledSource.Token);
                await StopAeration(true);
            }
            catch (TaskCanceledException) { }
            finally { aerateCancelledSource = null; }
        }