I am building a Windows Service in C#, and I have a method called OnStart, all of my bussiness logic is in a file named code.cs, how can I tell the OnStart method to call the stater method “starter” in code.cs?
/// <summary>
/// OnStart: Put startup code here
/// - Start threads, get inital data, etc.
/// </summary>
/// <param name="args"></param>
protected override void OnStart(string[] args)
{
base.OnStart(args);
}
OnStart needs to return in order for Windows to know the service is started. You should launch a new Thread in OnStart that calls your starter. Something like:
This assumes your current Starter method does not spawn it’s own thread. The key is to allow OnStart to return.