Sometimes some programs need to run as services, but cannot be made into services. For example, ActiveX controls are called on winform and ActiveX controls cannot be run in services.
There are two solutions:
1. Make a scheduled task. Here, the focus is on running the task before logging on to all users.
2. Start the winform program as a Service. The disadvantage is that you need to run two processes,CodeRefer to the following:
Code
Private Process = Null ;
Public Service1 ()
{
Initializecomponent ();
}
protected override void onstart ( string [] ARGs)
{< br> // Start the winform program, here, the winfrom program and service are in the same directory
Process = process. start (appdomain. currentdomain. basedirectory + " test.exe " );
}
Protected Override VoidOnstop ()
{
//Close winform Program
Process. closemainwindow ();
Process. Close ();
Process. Dispose ();
}