My problem is that I want to create a background application but with a user interface that could be restored and minimized to the system tray and it starts with windows. I trie
Here's a way to create an app that isn't tied to a Form. Use a Standard WinForms Project, but pass your custom implementation of ApplicationContext to Application.Run()
:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyContext());
}
}
public class MyContext : ApplicationContext
{
public MyContext()
{
// this is the new "entry point" for your application
// use Application.Exit() to shut down the application
// you can still create and display a NotifyIcon control via code for display in the tray
// (the icon for the NotifyIcon can be an embedded resource)
// you can also display forms as usual when necessary
}
}
Creating a form and hiding it is the way to go if you want your application to start when the user logs in.
If you want your code to run even if no user is logged-in, then you will require a windows service.
If you choose to go down that road, you most likely will want to have an application that, somehow, interacts with your service.