private void PlayAnimation(ILaserPattern pattern, PatternOptions options) { if (!AnimationCompleted() || options.AnimationSpeed.ToString() == AnimationSpeed.Off.ToString()) { return; } _laserAnimationStatus.AnimationCanceled = false; _animationTask = new Task(() => pattern.Project(options), TaskCreationOptions.LongRunning); _animationTask.Start(); _previousExecutedPatterns.Add(pattern); }
/// <summary> /// Plays the specified patternOptions, optional duration animation will stop after set milliseconds /// </summary> /// <param name="patternName"></param> /// <param name="animationSpeed"></param> /// <param name="duration"></param> public void PlayPattern(PatternOptions options) { if (!AnimationCompleted()) { return; } _playPatternTask = new Task(() => { ILaserPattern pattern = _patterns.Find(p => p.GetType().Name == options.PatternName); if (pattern == null) { return; } pattern.Project(options); }, TaskCreationOptions.RunContinuationsAsynchronously); _playPatternTask.Start(); }