Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8635731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:03:00+00:00 2026-06-12T10:03:00+00:00

How can I access and run a console application from a windows form ,

  • 0

How can I access and run a console application from a windows form, 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 Process.Start(path to console app) but this is not what I want. I want to access and use the Main method of the console application in my form project. This method would run at a click on a button.

This gives the following error.

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.

private void buttonApplication_Click(object sender, EventArgs e)
{
  Ch15Extra_2.Program.Main();
}

Here are the methods.

ConsoleApp:

namespace Ch15Extra_2
{
  public class Program
  {
    public static void Main()
    {
      Console.WriteLine("Here the app is running");
      Console.ReadKey();
    }
  }
}

Form1:

private void buttonApplication_Click(object sender, EventArgs e) { }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:03:01+00:00Added an answer on June 12, 2026 at 10:03 am

    If you need to run your console app without WinForms app, and sometimes you want to execute some console code without running a console app, I have a suggestion for you:

    You can divide your solution into three parts.

    1. WinForms part
    2. Console part
    3. Dll library.

    Link a dll to first and to the second projects.

    Then if you need to run shared code from WinFomrs app, you can do:

    private void buttonApplication_Click(object sender, EventArgs e)
    {
        var shared = new SharedClass();
        shared.Run();
    }
    

    SharedClass will be implemented in the third project.
    You can call it from console app too.


    upd

    Project 1 : ClassLibrary.

    public class SharedClass
    {
        public int DoLogic(int x)
        {
            return x*x;
        }
    }
    

    Proj 2. WinForms. Has a Reference to Project 1

    using Shared;

    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            TextBox textBox = new TextBox();
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                var shared = new SharedClass();
                textBox.Text = shared.DoLogic(10).ToString();
            }
        }
    }
    

    proj 3. Console App

        public class Program
        {
            public static void Main()
            {
                Console.WriteLine("Here the app is running");
                var shared = new Shared.SharedClass();
                Console.WriteLine(shared.DoLogic(10));
                Console.ReadKey();
            }
        }
    

    I’ve just checked – it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run my cap deploy, it complains that it can't access the log
I have an app deployed on Heroku. I can access the remote heroku console
I've got a .NET CF (C#) mobile application that I run on a windows
I have a project ongoing at the moment which is create a Windows Service
I have developed web application which uses JasperReports for reporting purpose. In that I
I've been playing around with chrome's console. I found that I can access the
Can anyone let me know how can access an element of a list that
As you know anyone can access strings in an native application using a hex
I've written a server in Delphi 2010 that needs to launch a console application
I have an application that works fine in Visual Studios 2008, and I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.