示例#1
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (IsRunning)
            {
                return;
            }

            SaveButton.IsEnabled       = false;
            ActivationButton.IsEnabled = false;
            string path = PathInput.Text;

            new Thread(new ThreadStart(() =>
            {
                OnMessage("Building map of the urls...", MessageType.Information);
                Stopwatch stopwatch = Stopwatch.StartNew();
                crawler.BuildSiteMap();
                string str = crawler.SiteMapToString();
                stopwatch.Stop();
                OnMessage($"Done. Took {stopwatch.ElapsedMilliseconds} ms", MessageType.Information);
                try
                {
                    System.IO.File.WriteAllText(path, str);
                    long filesize = new System.IO.FileInfo(path).Length;
                    OnMessage($"File saved to {path}. Size: {filesize / 1000} kb", MessageType.Information);
                }
                catch (Exception ex)
                {
                    OnMessage(ex.Message, MessageType.Error);
                }
                OnProgress(0.0);
                SaveButton.Dispatcher.Invoke(() => SaveButton.IsEnabled             = true);
                ActivationButton.Dispatcher.Invoke(() => ActivationButton.IsEnabled = true);
            })).Start();
        }