-
Create a new Console project in Visual Studio.
-
Download the
Bosbec.ServiceHost
package in the NuGet package manager. -
Change the content of your Main() method like this:
public static void Main() { ServiceHost.Create(new StructureMapContainerAdapter()) .Logging(l => l.ColoredConsole()) .ServiceFinder(f => f.ServicesInAssemblyOfType<Program>()) .Run(); }
-
Create a new C# file named
TimerService.cs
and paste this content:public class TimerService : IService, IRequireInitialization { private System.Timers.Timer _timer; public void Initialize() { _timer = new System.Timers.Timer(1000) { AutoReset = true, Enabled = true }; _timer.Elapsed += (sender, args) => Console.WriteLine("Ding dong!"); } public void Start() { _timer.Start(); } public void Stop() { _timer.Stop(); } }
-
That's it, you're ready to Debug the application and let the magic happen. You should see "Ding dong!" all over your screen along with some debugging information from the framework itself.
-
Notifications
You must be signed in to change notification settings - Fork 0
License
bosbec/servicehost
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published