private void RefreshCh(object sender, EventArgs e)//обновление окна сообщений    //Затратный алгоритм в плане  реурсов и трафика, гораздо более эффективно было бы, если вместо очистки списка добавлять новые элементы в конец
        {
            if (ban == false)
            {
                if (FullTextOfDialog != sql.DownloadChat(ChatID))// && FullTextOfDialog!=""
                {
                    FullTextOfDialog = sql.DownloadChat(ChatID);

                    /*
                     * Ava = new List<Image>();
                     * FilePic = new List<Image>();
                     * media = new List<MediaElement>();
                     * Restart = new List<System.Windows.Controls.Button>();
                     * PauseResume = new List<System.Windows.Controls.Button>();
                     * rewind = new List<System.Windows.Controls.Slider>();
                     * mediaPanel = new List<StackPanel>();
                     * Msg = new List<TextBlock>();
                     * SP = new List<StackPanel>();
                     * image1 = new List<BitmapImage>();
                     * time = new List<System.Windows.Controls.Label>();
                     * MediaTimer = new List<System.Windows.Forms.Timer>();
                     * TimerState = new List<bool>();
                     * state = new List<bool>();
                     * LBDialog.Items.Clear();*/
                    TextToListBox = FullTextOfDialog.Split('\n');
                    ToListBox();
                }
            }
        }
        public Messages(int id, int ChatID, bool isChat)
        {
            CurrentMediaElement = 0;
            sql         = new SqlAction();
            ID          = id;
            this.ChatID = ChatID;
            this.isChat = isChat;
            mediaIndex  = 0;
            j           = 0;
            i           = 0;
            InitializeComponent();
            FullTextOfDialog = sql.DownloadChat(ChatID);

            tm          = new System.Windows.Forms.Timer();
            tm.Interval = 1000;
            tm.Tick    += RefreshCh;
            tm.Enabled  = true;

            Ava         = new List <Image>();
            FilePic     = new List <Image>();
            media       = new List <MediaElement>();
            Restart     = new List <System.Windows.Controls.Button>();
            PauseResume = new List <System.Windows.Controls.Button>();
            rewind      = new List <System.Windows.Controls.Slider>();
            mediaPanel  = new List <StackPanel>();
            Msg         = new List <TextBlock>();
            SP          = new List <StackPanel>();
            image1      = new List <BitmapImage>();
            time        = new List <System.Windows.Controls.Label>();
            MediaTimer  = new List <System.Windows.Forms.Timer>();
            TimerState  = new List <bool>();
            state       = new List <bool>();
            if (FullTextOfDialog != "")
            {
                TextToListBox = FullTextOfDialog.Split('\n');
                ToListBox();
            }
        }