private void CountWords_Click(object sender, RoutedEventArgs e)
        {
           

            var words = processedText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            Dictionary<string, int> wordCount = new Dictionary<string, int>();

            MainTextBox.Text = "Количество                   Слово\r\n";
            MainTextBox.AppendText("--------------                  --------\r\n");

            this.Title = "CountWordsApp: counting...";

            Task.Factory.StartNew(() =>
                {
                    foreach (var word in words)
                    {
                        if (wordCount.ContainsKey(word))
                            wordCount[word]++;
                        else
                            wordCount[word] = 1;
                    }
                }).ContinueWith(prevTask => Dispatcher.Invoke(()=>
                {
                    this.Title = "CountWordsApp: preparing for displaying calculating results...";

                    foreach (var item in wordCount.OrderByDescending(k => k.Value))
                    {
                        string space = new string(' ', 29 - item.Value.ToString().Length);
                        string output = String.Format("        {0}{1}{2}\r\n", item.Value, space, item.Key);
                        MainTextBox.AppendText(output);
                    }

                    
                    firstW = new w1();
                    secondW = new w2();

                    firstW.w1TextBox.Text = "Cлова\r\n";
                    secondW.w2TextBox.Text = "Количество\r\n";

                    foreach (var item in wordCount.OrderByDescending(k => k.Value))
                    {
                        firstW.w1TextBox.AppendText(item.Key.ToString()+"\r\n");
                        secondW.w2TextBox.AppendText(item.Value.ToString() + "\r\n");

                    }

                    //firstW.Show();
                    //secondW.Show();
                    
                })).ContinueWith(prevTask => Dispatcher.Invoke(() => 
                {
                    int words_length = words.Length;
                    
                    int[] NumberOfWords = new int[11];
                    for (int i = 0; i <= 10; i++)
                        NumberOfWords[i] = wordCount.Where(item => item.Key.Length == i+1).Select(v => v.Value).Sum();
                    NumberOfWords[10] = wordCount.Where(item => item.Key.Length >= 11).Select(v => v.Value).Sum();
                    
                    this.Title = "CountWordsApp: done";

                    string str = String.Format("Обработано {0} слов(а/о)\r\n", words_length);
                    str += String.Format("Уникальных слов: {0}\r\n\r\n", wordCount.Keys.Count);
                    str += String.Format("Cлов длиной 1: {0} ({1:#.##}%)\r\n", NumberOfWords[0], (double)NumberOfWords[0] / words_length * 100);
                    str += String.Format("Cлов длиной 2: {0} ({1:#.##}%)\r\n", NumberOfWords[1], (double)NumberOfWords[1] / words_length * 100);
                    str += String.Format("Cлов длиной 3: {0} ({1:#.##}%)\r\n", NumberOfWords[2], (double)NumberOfWords[2] / words_length * 100);
                    str += String.Format("Cлов длиной 4: {0} ({1:#.##}%)\r\n", NumberOfWords[3], (double)NumberOfWords[3] / words_length * 100);
                    str += String.Format("Cлов длиной 5: {0} ({1:#.##}%)\r\n", NumberOfWords[4], (double)NumberOfWords[4] / words_length * 100);
                    str += String.Format("Cлов длиной 6: {0} ({1:#.##}%)\r\n", NumberOfWords[5], (double)NumberOfWords[5] / words_length * 100);
                    str += String.Format("Cлов длиной 7: {0} ({1:#.##}%)\r\n", NumberOfWords[6], (double)NumberOfWords[6] / words_length * 100);
                    str += String.Format("Cлов длиной 8: {0} ({1:#.##}%)\r\n", NumberOfWords[7], (double)NumberOfWords[7] / words_length * 100);
                    str += String.Format("Cлов длиной 9: {0} ({1:#.##}%)\r\n", NumberOfWords[8], (double)NumberOfWords[8] / words_length * 100);
                    str += String.Format("Cлов длиной 10: {0} ({1:#.##}%)\r\n", NumberOfWords[9], (double)NumberOfWords[9] / words_length * 100);
                    str += String.Format("Остальные слова: {0} ({1:#.##}%)\r\n", NumberOfWords[10], (double)NumberOfWords[10] / words_length * 100);

                    sw = new StatisticsWindow();
                    sw.Show();
                    sw.swTextBox.Text = str;

                }));
        }
        private void CountWords_Click(object sender, RoutedEventArgs e)
        {
            var words = processedText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            Dictionary <string, int> wordCount = new Dictionary <string, int>();

            MainTextBox.Text = "Количество                   Слово\r\n";
            MainTextBox.AppendText("--------------                  --------\r\n");

            this.Title = "CountWordsApp: counting...";

            Task.Factory.StartNew(() =>
            {
                foreach (var word in words)
                {
                    if (wordCount.ContainsKey(word))
                    {
                        wordCount[word]++;
                    }
                    else
                    {
                        wordCount[word] = 1;
                    }
                }
            }).ContinueWith(prevTask => Dispatcher.Invoke(() =>
            {
                this.Title = "CountWordsApp: preparing for displaying calculating results...";

                foreach (var item in wordCount.OrderByDescending(k => k.Value))
                {
                    string space  = new string(' ', 29 - item.Value.ToString().Length);
                    string output = String.Format("        {0}{1}{2}\r\n", item.Value, space, item.Key);
                    MainTextBox.AppendText(output);
                }


                firstW  = new w1();
                secondW = new w2();

                firstW.w1TextBox.Text  = "Cлова\r\n";
                secondW.w2TextBox.Text = "Количество\r\n";

                foreach (var item in wordCount.OrderByDescending(k => k.Value))
                {
                    firstW.w1TextBox.AppendText(item.Key.ToString() + "\r\n");
                    secondW.w2TextBox.AppendText(item.Value.ToString() + "\r\n");
                }

                //firstW.Show();
                //secondW.Show();
            })).ContinueWith(prevTask => Dispatcher.Invoke(() =>
            {
                int words_length = words.Length;

                int[] NumberOfWords = new int[11];
                for (int i = 0; i <= 10; i++)
                {
                    NumberOfWords[i] = wordCount.Where(item => item.Key.Length == i + 1).Select(v => v.Value).Sum();
                }
                NumberOfWords[10] = wordCount.Where(item => item.Key.Length >= 11).Select(v => v.Value).Sum();

                this.Title = "CountWordsApp: done";

                string str = String.Format("Обработано {0} слов(а/о)\r\n", words_length);
                str       += String.Format("Уникальных слов: {0}\r\n\r\n", wordCount.Keys.Count);
                str       += String.Format("Cлов длиной 1: {0} ({1:#.##}%)\r\n", NumberOfWords[0], (double)NumberOfWords[0] / words_length * 100);
                str       += String.Format("Cлов длиной 2: {0} ({1:#.##}%)\r\n", NumberOfWords[1], (double)NumberOfWords[1] / words_length * 100);
                str       += String.Format("Cлов длиной 3: {0} ({1:#.##}%)\r\n", NumberOfWords[2], (double)NumberOfWords[2] / words_length * 100);
                str       += String.Format("Cлов длиной 4: {0} ({1:#.##}%)\r\n", NumberOfWords[3], (double)NumberOfWords[3] / words_length * 100);
                str       += String.Format("Cлов длиной 5: {0} ({1:#.##}%)\r\n", NumberOfWords[4], (double)NumberOfWords[4] / words_length * 100);
                str       += String.Format("Cлов длиной 6: {0} ({1:#.##}%)\r\n", NumberOfWords[5], (double)NumberOfWords[5] / words_length * 100);
                str       += String.Format("Cлов длиной 7: {0} ({1:#.##}%)\r\n", NumberOfWords[6], (double)NumberOfWords[6] / words_length * 100);
                str       += String.Format("Cлов длиной 8: {0} ({1:#.##}%)\r\n", NumberOfWords[7], (double)NumberOfWords[7] / words_length * 100);
                str       += String.Format("Cлов длиной 9: {0} ({1:#.##}%)\r\n", NumberOfWords[8], (double)NumberOfWords[8] / words_length * 100);
                str       += String.Format("Cлов длиной 10: {0} ({1:#.##}%)\r\n", NumberOfWords[9], (double)NumberOfWords[9] / words_length * 100);
                str       += String.Format("Остальные слова: {0} ({1:#.##}%)\r\n", NumberOfWords[10], (double)NumberOfWords[10] / words_length * 100);

                sw = new StatisticsWindow();
                sw.Show();
                sw.swTextBox.Text = str;
            }));
        }