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(); }); }
/// <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(); }