public async void HandleTimelapseCalculations(TimeSpan timeLapseInterval, Double endDuration)
        {
            if (((machine.TimelapseConst.StartNow || machine.TimelapseConst.TlStartDate <= DateTime.Now)) &&
                endDuration > 0)
            {
                log.Info("Running single timelapse cycle");
                tokenSource        = new CancellationTokenSource();
                runningSingleCycle = true;
                log.Debug("TimeLapse Single Cycle Executed at: " + DateTime.Now);

                //may need await, we will see
                Task.Factory.StartNew(
                    () =>
                {
                    SingleCycle();
                });

                try
                {
                    await RunSingleTimeLapse(timeLapseInterval, tokenSource.Token);
                }
                catch (TaskCanceledException e)
                {
                    log.Error("TimeLapse Cancelled: " + e);
                    stopTimelapse();
                    return;
                }
                catch (Exception e)
                {
                    log.Error("Unknown timelapse error: " + e);
                }



                HandleTimelapseCalculations(timeLapseInterval, endDuration - timeLapseInterval.TotalMilliseconds);
            }
            else if (machine.TimelapseConst.TlStartDate > DateTime.Now)
            {
                await WaitForStartNow();

                HandleTimelapseCalculations(timeLapseInterval, endDuration);
            }
            else
            {
                log.Info("TimeLapse Finished");
                runningTimeLapse = false;
                Dispatcher.Invoke(() =>
                {
                    TimelapseCountTextBox.Clear();
                    TimelapseEndTimeTextBox.Clear();
                });
                return;
            }
        }
        public void stopTimelapse()
        {
            if (tokenSource != null)
            {
                tokenSource.Cancel();
            }
            Dispatcher.Invoke(() =>
            {
                TimelapseCountTextBox.Clear();
                TimelapseEndTimeTextBox.Clear();
            });

            runningTimeLapse = false;
            log.Debug("Timelapse stopped manually");
        }