public void CleanPanel()
        {
            while (DateTime.UtcNow < CleanDanmakuTime)
            {
                Thread.Sleep(200);
            }

            uint count = 0;

            Dispatcher.Invoke(() =>
            {
                double offset = 0;
                while (DanmakuPanel.Children.Count > 5000)
                {
                    FrameworkElement frameworkElement = (FrameworkElement)DanmakuPanel.Children[0];
                    offset += frameworkElement.ActualHeight;
                    DanmakuPanel.Children.RemoveAt(0);
                    count++;
                }
                double verticalOffset = DanmakuScrollViewer.VerticalOffset - offset;
                if (verticalOffset < 0)
                {
                    verticalOffset = 0;
                }
                DanmakuFluidMove.Duration = new Duration(TimeSpan.FromSeconds(0));
                DanmakuScrollViewer.ScrollToVerticalOffset(verticalOffset);

                DanmakuScrollViewer.InvalidateArrange();
                DanmakuScrollViewer.UpdateLayout();

                DanmakuFluidMove.Duration = new Duration(TimeSpan.FromSeconds(0.2));
            });

            Console.WriteLine("Danmaku cleaned : {0}", count);
        }
        public void AppendGift(GiftCacheManager.GiftCache item)
        {
            Dispatcher.Invoke(() =>
            {
                DanmakuPanel.Children.Add(new Gift(item));
                if (!DanmakuScrollViewer.IsMouseOver)
                {
                    DanmakuScrollViewer.ScrollToBottom();
                }
                CleanDanmakuTime = DateTime.UtcNow.AddSeconds(0.2);
            });

            if (CleanDanmakuTask == null || CleanDanmakuTask.IsCompleted)
            {
                CleanDanmakuTask = Task.Factory.StartNew(CleanPanel);
            }
        }
        public void AppendRoomBlock(BiliLiveJsonParser.RoomBlock item)
        {
            Dispatcher.Invoke(() =>
            {
                DanmakuPanel.Children.Add(new RoomBlock(item));
                if (!DanmakuScrollViewer.IsMouseOver)
                {
                    DanmakuScrollViewer.ScrollToBottom();
                }
                CleanDanmakuTime = DateTime.UtcNow.AddSeconds(0.2);
            });

            if (CleanDanmakuTask == null || CleanDanmakuTask.IsCompleted)
            {
                CleanDanmakuTask = Task.Factory.StartNew(CleanPanel);
            }
        }
        public void AppendGift(BiliLiveJsonParser.Gift item)
        {
            Dispatcher.Invoke(() =>
            {
                //if (Gift.AppendGiftToExist(item))
                //    return;
                DanmakuPanel.Children.Add(new Gift(item));
                if (!DanmakuScrollViewer.IsMouseOver)
                {
                    DanmakuScrollViewer.ScrollToBottom();
                }
                CleanDanmakuTime = DateTime.UtcNow.AddSeconds(0.2);
            });

            if (CleanDanmakuTask == null || CleanDanmakuTask.IsCompleted)
            {
                CleanDanmakuTask = Task.Factory.StartNew(CleanPanel);
            }
        }