I have created an Windows application without showing a window form. I need to keep my application running . Now after executing all the codes application become stopped.
I try a way like below.
public void RunForm()
{
var frm=new Form();
Application.Run(frm);
}
the application is not stopped but showing form. How can i keep running my application without showing the form?
Just call Application.Run() and don’t pass anything. It belongs in your Main() method.
This keeps your main thread active and responsive to Windows notifications. Of course, there are not a lot of them since you don’t have a user interface anymore. Timers will work. A NotifyIcon will work. A hot key registered by pinvoking RegisterHotKey() will work. A low-level windows hook will work.
And SystemEvents will work. Which is important, you’ll need to subscribe its SessionEnding event to know when the user is logging off or shutting down Windows, you’ll need to terminate your app. Which you do by calling Application.ExitThread().