I want to open a console in wpf, I was try to open the console twice without close the program, but in the second time the program crashed, I don't really know why and I'd love to help
using System;
using System.Windows;
using System.Runtime.InteropServices;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
[DllImport("Kernel32")]
public static extern void AllocConsole();
[DllImport("Kernel32")]
public static extern void FreeConsole();
private void button_Click(object sender, RoutedEventArgs e)
{
AllocConsole();
string x = Console.ReadLine();
FreeConsole();
}
}
}