private void Disconnbtn_OnClick(object sender, RoutedEventArgs e)
 {
     lock (DanmuHecheng)
     {
         while (true)
         {
             if (DanmuHecheng.Any())
             {
                 _ = DanmuHecheng.Dequeue();
             }
             else
             {
                 break;
             }
         }
     }
     ConnBtn.IsEnabled = true;
     getDanmakuThread.Abort();
     getDanmakuThread = new Thread(() =>
     {
         while (true)
         {
             if (b.isLive)
             {
                 b.GetDanmaku();
                 Thread.Sleep(1000);
             }
             else
             {
                 Thread.Sleep(100000);
             }
         }
     })
     {
         IsBackground = true
     };
     logging(Logger.SaveToggle());
     isSaveToggle = true;
 }
        public MainWindow()
        {
            InitializeComponent();

            Info.Text += version;
            //初始化日志
            //b = new Api();
            b = new XiguaAPI();
            overlay_enabled = true;
            OpenOverlay();
            overlay.Show();

            Closed += MainWindow_Closed;

            //Api.OnMessage += b_ReceivedDanmaku;
            //Api.OnLeave += OnLiveStop;
            //            b.OnMessage += ProcDanmaku;
            //Api.LogMessage += b_LogMessage;
            //Api.OnRoomCounting += b_ReceivedRoomCount;

            XiguaAPI.OnMessage      += b_ReceivedDanmaku;
            XiguaAPI.OnLeave        += OnLiveStop;
            XiguaAPI.LogMessage     += b_LogMessage;
            XiguaAPI.OnRoomCounting += b_ReceivedRoomCount;

            YuYin.LogMessage += b_LogMessage;
            //YuYin.Landu += Landu;

            timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, FuckMicrosoft,
                                        Dispatcher);
            timer.Start();

            Log.DataContext = _messageQueue;

            releaseThread = new Thread(() =>
            {
                while (true)
                {
                    Utils.ReleaseMemory(true);
                    Thread.Sleep(30 * 1000);
                }
            });
            releaseThread.IsBackground = true;
            getDanmakuThread           = new Thread(() =>
            {
                while (true)
                {
                    if (b.isLive)
                    {
                        b.GetDanmaku();
                        Thread.Sleep(1000);
                    }
                    else
                    {
                        Thread.Sleep(100000);
                    }
                }
            });
            getDanmakuThread.IsBackground = true;
            //            releaseThread.Start();
            ProcDanmakuThread = new Thread(() =>
            {
                while (true)
                {
                    lock (_danmakuQueue)
                    {
                        var count = 0;
                        if (_danmakuQueue.Any())
                        {
                            count = (int)Math.Ceiling(_danmakuQueue.Count / 30.0);
                        }

                        for (var i = 0; i < count; i++)
                        {
                            if (_danmakuQueue.Any())
                            {
                                var danmaku = _danmakuQueue.Dequeue();
                                ProcDanmaku(danmaku);
                            }
                        }
                    }

                    Thread.Sleep(25);
                }
            })
            {
                IsBackground = true
            };
            ProcDanmakuThread.Start();

            for (var i = 0; i < 100; i++)
            {
                _messageQueue.Add("");
            }
            logging("可以点击日志复制到剪贴板");

            Loaded            += MainWindow_Loaded;
            Setting.GetConfig += GetConfig;
            Setting.GetYuyin  += GetYuyin;
            YuYin.GetConfig   += GetConfig;
            XiguaAPI.GetYuyin += GetYuyin;
            //Landu();
            YuYin.HeCheng();

            System.IO.Directory.CreateDirectory("log");    //创造日志文件夹
            System.IO.Directory.CreateDirectory("toggle"); //创造记录文件夹
            try
            {
                ConfigData = (ConfigData)Config.Read();
                UpdateUI();
            }
            catch
            {
                ConfigData = new ConfigData();
                Config.Write(ConfigData);
                UpdateUI();
                MessageBox.Show("    欢迎使用西瓜直非官方助手。\n    本软件原作者 q792602257 ,当前分支由 挂神 维护。\n    本软件完全开源,挂神不会以任何形式销售本软件,严禁倒卖。\n    更多说明请前往 更多设置-关于程序 查看,或翻阅软件附带的“说明”文件。\n    您可以在关闭软件后将原安装目录下的Config.json文件覆盖本目录下的Config.json进行配置迁移。", "关于本软件");
            }
#if DEBUG
            ConfigData.DeBug = true;
#endif

            BlackList        = ConfigData.BlackList.Split('|');
            User.targetBrand = ConfigData.Brand;
            YuYin.version    = version;
            YuYin.Connect();
        }