我能够创建一个简单的Windows服务应用程序,只是框架而已,但我仍然感到困惑。在哪里放置我的代码以使Windows服务实际执行任务呢?我有一个单独的程序,我想在这里包含、调用或合并。我应该把程序放在哪里?我从哪里开始?
public partial class MyNewService : ServiceBase
{
public MyNewService()
{
InitializeComponent();
if (!System.Diagnostics.EventLog.SourceExists("MySource"))
{
System.Diagnostics.EventLog.CreateEventSource(
"MySource", "MyNewLog");
}
eventLog1.Source = "MySource";
eventLog1.Log = "MyNewLog";
}
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// Change the following line to match.
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new MyNewService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
}
}