I have a basic app that asks user to 'Press any key or Enter to exit'. The purpose of implementing my app this way is to have it running till the system shuts down or the user logs out. But I want to have it invisible so the user doesn't accidentally close it when pressing a key intended for another program. The structure of my program is:
using System;
namespace myApp
{
class Program
{
private static void Main()
{
// Some code here
// do not close until closed manually
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
public static void Method1 ()
{
// some code here
}
public static void Method2 ()
{
// some code for method 2 here
}
}
}
In a similar post, people are suggesting solutions that are either little advanced or do not work for me, e.g.
- Changing into a Windows service application,
- Running the .exe file of the program as a task,
- Outputting this console app as a Windows app,
- Starting the VS project as a Windows Form application then not calling any forms, etc.
But this does not work for me. Let me describe why. I have tried options 3 and 4 above, but my app completely disappears/closes, I check the task manager thinking it is may be running in the background but it is not there and that means it closes straight away.
I feel changing the app to a windows service will complicate things for my ClickOnce app. As for 2, people have suggested to open the program as a task and hide the window, but I am not sure how I can do this in the code itself without calling it externally as .exe application. Thank you in advance.