Business.MpcPlayerBusiness.timerGetPosition_Tick C# (CSharp) Method

timerGetPosition_Tick() private method

Occurs every second. Detects end position, start position or restore position.
private timerGetPosition_Tick ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        private async void timerGetPosition_Tick(object sender, EventArgs e) {
            if (TimerGetPositionEnabled) {
                if ((EndPos.HasValue && position > EndPos && !IgnorePos) || position > CurrentVideo.Length - 1) {
                    // End position reached.
                    if (PlayNext != null) {
                        PlayNext(this, new EventArgs());
                        return;
                    }
                } else if (restorePosition == 0 && position < 10 && StartPos.HasValue && StartPos > 10 && position < StartPos && !IgnorePos) {
                    // Skip to start position.
                    restorePosition = StartPos.Value;
                }

                if (restorePosition > 0) {
                    // Restore to specified position (usually after a crash).
                    if (restorePosition > 10) {
                        TimerGetPositionEnabled = false;
                        position = restorePosition;
                        restorePosition = 0;

                        await Task.Delay(1000);
                        await apiAccess.SetPositionAsync((int)position);
                        await Task.Delay(1000);
                        TimerGetPositionEnabled = true;
                    } else
                        restorePosition = 0;
                } else
                    await apiAccess.GetCurrentPositionAsync();
            }
        }