Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to write a single purpose app with no processing output?

How to write a single purpose app with no processing output?

Scheduled Pinned Locked Moved C#
tutorialquestioncsharpdiscussion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    michal kreslik
    wrote on last edited by
    #1

    Hello, what is the best way on how to write a single purpose app with no processing output in C#? For the sake of an example, let's say that your app's only task is to rename a file (given as the parameter) to "foo" and then exit. If I code this as a console app, I'll get a console window that opens during the (however short) execution. I can also code this as a windows app, but then I'd have to set the main form's .Visible property to false upon start. That doesn't look like the most professional way on how to accomplish this task, apart from the fact that referencing and loading System.Windows.Forms etc is very inefficient if I'm not going to use these libraries anyway. Then again, if I code this as a windows service, this app can't be started from the command line. Anyone have any thoughts? Thanks, Michal

    C B 2 Replies Last reply
    0
    • M michal kreslik

      Hello, what is the best way on how to write a single purpose app with no processing output in C#? For the sake of an example, let's say that your app's only task is to rename a file (given as the parameter) to "foo" and then exit. If I code this as a console app, I'll get a console window that opens during the (however short) execution. I can also code this as a windows app, but then I'd have to set the main form's .Visible property to false upon start. That doesn't look like the most professional way on how to accomplish this task, apart from the fact that referencing and loading System.Windows.Forms etc is very inefficient if I'm not going to use these libraries anyway. Then again, if I code this as a windows service, this app can't be started from the command line. Anyone have any thoughts? Thanks, Michal

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      michal.kreslik wrote:

      I can also code this as a windows app, but then I'd have to set the main form's .Visible property to false upon start.

      Why would you create the form in the first place? All you need to do is rewrite the Program.Main method (in Program.cs) to not create or open the form.


      Upcoming FREE developer events: * Developer Day Scotland My website

      M 1 Reply Last reply
      0
      • C Colin Angus Mackay

        michal.kreslik wrote:

        I can also code this as a windows app, but then I'd have to set the main form's .Visible property to false upon start.

        Why would you create the form in the first place? All you need to do is rewrite the Program.Main method (in Program.cs) to not create or open the form.


        Upcoming FREE developer events: * Developer Day Scotland My website

        M Offline
        M Offline
        michal kreslik
        wrote on last edited by
        #3

        Thanks, cool. I removed the Form and all extra references from the project. Then I'm wondering - what is causing the console app project to open a console window then? Thanks, Michal

        M 1 Reply Last reply
        0
        • M michal kreslik

          Thanks, cool. I removed the Form and all extra references from the project. Then I'm wondering - what is causing the console app project to open a console window then? Thanks, Michal

          M Offline
          M Offline
          michal kreslik
          wrote on last edited by
          #4

          Ok, I can see it now: console app's output type in the .csproj file is: Exe while the windows app's output type is: WinExe The "Exe" output type forces the application to open a new console window, while the "WinExe" doesn't open any console window. Thus, the best way on how to accomplish the above task is to create a console application and switch the output type to "Windows Application" in the project Properties > Application. Thanks, Michal

          1 Reply Last reply
          0
          • M michal kreslik

            Hello, what is the best way on how to write a single purpose app with no processing output in C#? For the sake of an example, let's say that your app's only task is to rename a file (given as the parameter) to "foo" and then exit. If I code this as a console app, I'll get a console window that opens during the (however short) execution. I can also code this as a windows app, but then I'd have to set the main form's .Visible property to false upon start. That doesn't look like the most professional way on how to accomplish this task, apart from the fact that referencing and loading System.Windows.Forms etc is very inefficient if I'm not going to use these libraries anyway. Then again, if I code this as a windows service, this app can't be started from the command line. Anyone have any thoughts? Thanks, Michal

            B Offline
            B Offline
            blackjack2150
            wrote on last edited by
            #5

            I did this more than once with Windows applications. I wrote the useful code in the constructor of the form, but didn't show the form. In Program.cs , instead of Form.Show(new ManiForm()); I just wrote new MainForm();

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups