Closing Console Window From WPF

2019-08-13 02:39发布

问题:

I have a WPF project, when you click on a button, a Console application window Appears and do a long task (crawling some url that it got it from the wpf window). All of this works good, I have 2 problems.

  1. while the Console window is on, the WPF window freezes.
  2. if I closed the Console window, the whole application closes (including the wpf window).

For the Console Window, I implemented the class from John Leidegren in this post: No output to console from a WPF application?

then from my WPF project:

        public void StartCrawler (string url)
        {
        ConsoleManager.Show();
        Console.BufferHeight = Int16.MaxValue - 1;
        Console.SetWindowSize(122, 54);
          //using methods to display and crawl the given site
          //showing Console Messages for users with which sites are crowled  

        }

Is there any way to unfreeze my WPF project and when the Console window closes it doesn't affect it ? apart from creating a Console Application project and refer to its .exe ?

Thanks in advance.