7 Replies - 10628 Views - Last Post: 30 July 2011 - 08:20 PM Rate Topic: -----

#1 DMK741  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 13-January 11

Windows Form and Command Line in the same application

Posted 29 July 2011 - 05:38 PM

Is there a way I can get both a command line AND a windows form to run in the same application? How do I handle threading for this?
Is This A Good Question/Topic? 0
  • +

Replies To: Windows Form and Command Line in the same application

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Windows Form and Command Line in the same application

Posted 29 July 2011 - 08:25 PM

Yes. Create a winforms application. Go to the project properties (Project menu, last line). On the Application tab you should see a dropdown list named Output Type. Change this to Console Application.

There, you have both a window and a console.

This should be put in a FAQ somewhere :)

This post has been edited by Momerath: 29 July 2011 - 08:25 PM

Was This Post Helpful? 0
  • +
  • -

#3 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4531
  • View blog
  • Posts: 7,902
  • Joined: 08-June 10

Re: Windows Form and Command Line in the same application

Posted 29 July 2011 - 09:28 PM

Too short for a tutorial, no code for a snippet. But I can add this thread to the C# References thread (for all the good that seems to be doing).
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5578
  • View blog
  • Posts: 11,918
  • Joined: 02-June 10

Re: Windows Form and Command Line in the same application

Posted 30 July 2011 - 07:40 AM

View PostMomerath, on 29 July 2011 - 09:25 PM, said:

Yes. Create a winforms application. Go to the project properties (Project menu, last line). On the Application tab you should see a dropdown list named Output Type. Change this to Console Application.

There, you have both a window and a console.

This should be put in a FAQ somewhere :)


Really? I don't see it get asked a lot. Maybe I'm just missing it. The only time I do this is during debugging so I can watch my Console.WriteLine statements. Which of course don't execute on release versions.

#if DEBUG
    Console.WriteLine("Widget method started");
    // lots of method lines
    Console.WriteLine("Widget method completed");
#endif


I've added it to my personal FAQ response, in case I see it asked in the future.
Was This Post Helpful? 1
  • +
  • -

#5 DMK741  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 13-January 11

Re: Windows Form and Command Line in the same application

Posted 30 July 2011 - 12:37 PM

View PosttlhIn`toq, on 30 July 2011 - 07:40 AM, said:

The only time I do this is during debugging so I can watch my Console.WriteLine statements. Which of course don't execute on release versions.

#if DEBUG
    Console.WriteLine("Widget method started");
    // lots of method lines
    Console.WriteLine("Widget method completed");
#endif


This is mainly what I was going to use it for. Debugging; being able to track what's going on, but outside of the IDE.

I was playing around with stuff, and I also found out that I can just run Application.Run(form_goes_here) on a new thread, and as long as I started that thread from the main application process, both windows close when I exit the main application.
Was This Post Helpful? 0
  • +
  • -

#6 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4531
  • View blog
  • Posts: 7,902
  • Joined: 08-June 10

Re: Windows Form and Command Line in the same application

Posted 30 July 2011 - 02:09 PM

You can see console output in the View-> Output window as well.
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5578
  • View blog
  • Posts: 11,918
  • Joined: 02-June 10

Re: Windows Form and Command Line in the same application

Posted 30 July 2011 - 05:43 PM

View PostCurtis Rutland, on 30 July 2011 - 03:09 PM, said:

You can see console output in the View-> Output window as well.


View PostDMK741, on 30 July 2011 - 01:37 PM, said:

This is mainly what I was going to use it for. Debugging; being able to track what's going on, but outside of the IDE.

Was This Post Helpful? 0
  • +
  • -

#8 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4531
  • View blog
  • Posts: 7,902
  • Joined: 08-June 10

Re: Windows Form and Command Line in the same application

Posted 30 July 2011 - 08:20 PM

Ah, missed that.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1