Example #1
0
        private void Update()
        {
            if (!isInit)
            {
                return;
            }
            long preSpinCount = spinCount;

            if (isMoving)
            {
                moveValue += speed * 0.1f;
            }
            while (moveValue >= 1f)
            {
                moveValue -= 1f;
                CursorUp();
            }
            while (moveValue <= -1f)
            {
                moveValue += 1f;
                CursorDown();
            }
            if (preSpinCount != spinCount) //커서가 변경되었을 때
            //다음 커서값 설정하기
            {
                if (cursorRequest != null)
                {
                    if (dir == RotateDirection.Down)
                    {
                        cursors[cursors.Count - 1] = cursorRequest.settingCursor - cursorRequest.waitCount;
                    }
                    else
                    {
                        cursors[0] = cursorRequest.settingCursor + cursorRequest.waitCount;
                    }
                    cursorRequest.waitCount -= 1;
                    cursorRequest            = null;
                }
                if (stopRequest > 0)
                {
                    stopRequest--;
                }
                if (stopRequest == 0)
                {
                    moveValue = 0f;
                    ApplyMoveValue();
                    state = ReelState.Idle;
                    OnStoped?.Invoke();
                }

                UpdateRenderAll();
                OnCursorChanged?.Invoke(cursor);
            }
        }
Example #2
0
 public void Stop()
 {
     if (_isFinished)
     {
         return;
     }
     _isFinished = true;
     Task.WaitAll(_executeTaskList.ToArray());
     Thread.Sleep(1);
     OnStoped?.Invoke();
     Clear();
 }
Example #3
0
        private void Loop()
        {
            _nextWakeUpTickTime = Stopwatch.GetTimestamp();

            try
            {
                while (true)
                {
                    _nextWakeUpTickTime += _cycleTimeInTicks;

                    while (true)
                    {
                        long ticks = _nextWakeUpTickTime - Stopwatch.GetTimestamp();
                        if (ticks <= 0L)
                        {
                            break;
                        }
                        long diff = (ticks * 1000) / Stopwatch.Frequency; // cycle in milliseconds

                        if (diff >= 100)
                        {
                            Thread.Sleep(20);
                        }
                        else if (diff >= 40)
                        {
                            Thread.Sleep(10);
                        }
                        else if (diff >= 25)
                        {
                            Thread.Sleep(2);
                        }
                        else if (diff >= 15)
                        {
                            Thread.Sleep(1);
                        }
                        else if (diff >= 5)
                        {
                            Thread.SpinWait(200);
                        }
                        else if (diff > 1)
                        {
                            Thread.SpinWait(100);
                        }
                        else
                        {
                            Thread.SpinWait(10);
                        }
                    }

                    long lDelay = Stopwatch.GetTimestamp() - _nextWakeUpTickTime;

                    if (lDelay < _MaxDelayInTicks)
                    {
                        OnTimer?.Invoke(null, null);
                    }
                    else
                    {
                        OnSkipped?.Invoke(null, null);
                    }
                }
            }
            catch (ThreadInterruptedException) { }
            catch (Exception) { Console.WriteLine("Exiting timer thread."); }

            OnStoped?.Invoke(null, null);
        }
Example #4
0
 private void BluetoothLEWatcher_Stoped(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementWatcherStoppedEventArgs args)
 {
     OnStoped?.Invoke(this, null);
 }