示例#1
0
 void ControllSpawnEnemyInTime()
 {
     timer = Timers.TimerFactory.CreateTimer(Timers.TimerType.Seconds, 1);
     timer.ElapsedEvent += EnemyRandomSpawn;
     InitControlSpawnTime();
     timer.Start(this.spawnTime);
 }
示例#2
0
        [OuterLoop] // involves long delay
        public async Task WebSocketKeepsDotnetTimersOnlyLightlyThrottled()
        {
            double   maxDelayMs         = 0;
            double   maxLightDelayMs    = 0;
            DateTime start              = DateTime.Now;
            CancellationTokenSource cts = new CancellationTokenSource();

            using (ClientWebSocket cws = await WebSocketHelper.GetConnectedWebSocket(Test.Common.Configuration.WebSockets.RemoteEchoServer, TimeOutMilliseconds, _output))
            {
                await SendAndReceive(cws, "test");

                using (var timer = new Timers.Timer(fastTimeoutFrequency))
                {
                    DateTime last     = DateTime.Now;
                    DateTime lastSent = DateTime.MinValue;
                    timer.AutoReset = true;
                    timer.Enabled   = true;
                    timer.Elapsed  += async(object?source, Timers.ElapsedEventArgs? e) =>
                    {
                        var ms     = (e.SignalTime - last).TotalMilliseconds;
                        var msSent = (e.SignalTime - lastSent).TotalMilliseconds;
                        if (maxDelayMs < ms)
                        {
                            maxDelayMs = ms;
                        }
                        if (ms > moreThanLightThrottlingThreshold)
                        {
                            // fail fast, we are throttled heavily
#if DEBUG
                            Console.WriteLine("Too slow tick " + ms);
#endif
                            cts.Cancel();
                        }
                        else if (ms > detectLightThrottlingThreshold)
                        {
                            maxLightDelayMs = ms;
                            // we are lightly throttled
#if DEBUG
                            Console.WriteLine("Slow tick WS " + ms);
#endif
                        }
                        if (msSent > webSocketMessageFrequency)
                        {
                            await SendAndReceive(cws, "test");

                            lastSent = DateTime.Now;
                        }
                        last = e.SignalTime;
                    };

                    // test it for 10 minutes
                    try { await Task.Delay(10 * 60 * 1000, cts.Token); } catch (Exception) { }
                    timer.Close();
                }
                await cws.CloseAsync(WebSocketCloseStatus.NormalClosure, "WebSocketKeepsDotnetTimersOnlyLightlyThrottled", CancellationToken.None);
            }
            Assert.True(maxDelayMs > detectLightThrottlingThreshold, "Expect that it throttled lightly " + maxDelayMs);
            Assert.True(maxDelayMs < moreThanLightThrottlingThreshold, "Expect that it wasn't heavily throttled " + maxDelayMs);
        }
 internal BackupRescheduleTimer(Action timerCallback)
 {
     this._rescheduleTimer = new Timers.Timer {
         AutoReset = false
     };
     this._rescheduleTimer.Elapsed += RescheduleTimerOnElapsed;
     this._timerCallback            = timerCallback;
 }
示例#4
0
 internal RescheduleTimer(Action timerCallback, string TraceType)
 {
     this._rescheduleTimer = new Timers.Timer {
         AutoReset = false
     };
     this._rescheduleTimer.Elapsed += RescheduleTimerOnElapsed;
     this._timerCallback            = timerCallback;
     this.TraceType = TraceType;
 }
示例#5
0
 public ProcessBarEx()
 {
     this.Size = new  Size(100, 3);
     this.SetStyle(
         ControlStyles.UserPaint |                          //控件自行绘制,而不使用操作系统的绘制
         ControlStyles.AllPaintingInWmPaint |               //忽略擦出的消息,减少闪烁。
         ControlStyles.OptimizedDoubleBuffer |              //在缓冲区上绘制,不直接绘制到屏幕上,减少闪烁。
         ControlStyles.ResizeRedraw |                       //控件大小发生变化时,重绘。
         ControlStyles.SupportsTransparentBackColor, true); //支持透明背景颜色
     System.Timers.Timer timer = new Timers.Timer(40);
     timer.Elapsed += timer_Elapsed;
     timer.Start();
     this.Disposed += ((s, e) => { timer.Stop(); });
 }
示例#6
0
        [OuterLoop] // involves long delay
        // this test is influenced by usage of WS on the same browser tab in previous unit tests. we may need to wait long time for it to fizzle down
        public async Task DotnetTimersAreHeavilyThrottledWithoutWebSocket()
        {
            double   maxDelayMs         = 0;
            double   maxLightDelayMs    = 0;
            DateTime start              = DateTime.Now;
            CancellationTokenSource cts = new CancellationTokenSource();

            using (var timer = new Timers.Timer(fastTimeoutFrequency))
            {
                DateTime last = DateTime.Now;
                timer.AutoReset = true;
                timer.Enabled   = true;
                timer.Elapsed  += (object?source, Timers.ElapsedEventArgs? e) =>
                {
                    var ms = (e.SignalTime - last).TotalMilliseconds;
                    if (maxDelayMs < ms)
                    {
                        maxDelayMs = ms;
                    }
                    if (ms > moreThanLightThrottlingThreshold)
                    {
#if DEBUG
                        Console.WriteLine("Too slow tick " + ms);
#endif
                        // stop, we are throttled heavily, this is what we are looking for
                        cts.Cancel();
                    }
                    else if (ms > detectLightThrottlingThreshold)
                    {
                        maxLightDelayMs = ms;
                        // we are lightly throttled
#if DEBUG
                        Console.WriteLine("Slow tick NO-WS " + ms);
#endif
                    }
                    last = e.SignalTime;
                };

                // test it for 10 minutes
                try { await Task.Delay(10 * 60 * 1000, cts.Token); } catch (Exception) { }
                timer.Close();
            }
            Assert.True(maxDelayMs > detectLightThrottlingThreshold, "Expect that it throttled lightly " + maxDelayMs);
            Assert.True(maxDelayMs > moreThanLightThrottlingThreshold, "Expect that it was heavily throttled " + maxDelayMs);
        }
        /// <summary>
        /// Add a seekios to the list OnDemand
        /// Start the count down
        /// </summary>
        public void AddSeekiosOnDemand(SeekiosDTO seekios, DateTime dateEndRefreshTimer)
        {
            // setup the seekios on demand
            var seekiosOnDemand = new SeekiosOnDemand()
            {
                Seekios             = seekios,
                DateEndRefreshTimer = dateEndRefreshTimer
            };
            // setup the timer
            var timer = new Timers.Timer();

            timer.Interval  = new TimeSpan(0, 0, 1);
            timer.CountDown = (dateEndRefreshTimer - DateTime.Now).TotalSeconds;
            timer.Tick      = async() =>
            {
                if (timer.CountDown <= 0)
                {
                    timer.Stop();
                    seekiosOnDemand.OnFailed?.Invoke();
                    App.Locator.Map.LsSeekiosOnDemand.Remove(seekiosOnDemand);
                    var dialogService = GalaSoft.MvvmLight.Ioc.SimpleIoc.Default.GetInstance <Interfaces.IDialogService>();
                    await dialogService.ShowMessage(string.Format(Resources.OnDemandMessageFailedBody
                                                                  , seekios.SeekiosName)
                                                    , Resources.OnDemandMessageFailedTitle);
                }
                else
                {
                    timer.UpdateUI?.Invoke();
                    timer.CountDown--;
                }
            };
            seekiosOnDemand.Timer = timer;
            // add the seekios in the list that contains all the seekios in refreshing state (OnDemand)
            App.Locator.Map.LsSeekiosOnDemand.Add(seekiosOnDemand);
            // start the timer
            timer.Start();
        }
示例#8
0
 protected internal TimerEventArgs(Timers.Timer timer)
 {
     GondwanaTimer = timer;
 }
示例#9
0
 protected internal TimerEventArgs(Timers.Timer timer)
 {
     GondwanaTimer = timer;
 }