How to write a single purpose app with no processing output?
-
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
-
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
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
-
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
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
-
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
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
-
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
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 wrotenew MainForm();