title: Calling `Main` method of a console application from a form application (by a button click event)
body: <p><strong>How can I access and run a console application from a windows form</strong>, which is part of the same project. I have a windows form and a console application. I think that I can publish the console application and then use <code>Process.Start(path to console app)</code> but this is not what I want. I want to access and use the <code>Main</code> method of the console application in my form project. This method would run at a click on a button.</p>
  
  <p>This gives the following error.</p>
  
  <blockquote>
    <p>InvalidOperationException was unhandled
    Cannot read keys when either application does not have a console 
    or when console input has been redirected from a file. Try Console.Read.</p>
  </blockquote>
  
  <pre><code>private void buttonApplication_Click(object sender, EventArgs e)
  {
    Ch15Extra_2.Program.Main();
  }
  </code></pre>
  
  <p>Here are the methods.</p>
  
  <p>ConsoleApp:</p>
  
  <pre><code>namespace Ch15Extra_2
  {
    public class Program
    {
      public static void Main()
      {
        Console.WriteLine("Here the app is running");
        Console.ReadKey();
      }
    }
  }
  </code></pre>
  
  <p>Form1:</p>
  
  <pre><code>private void buttonApplication_Click(object sender, EventArgs e) { }
  </code></pre>