تبدیل برنامههای کنسول ویندوز به سرویس ویندوز ان تی
نویسنده: وحید نصیری
تاریخ: ۱۳۹۲/۰۸/۲۵ ۱۶:۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
PM> Install-Package Topshelf
using Topshelf;
namespace MyService
{
class Program
{
static void Main(string[] args)
{
HostFactory.Run(config =>
{
config.Service(settings => new TestService());
config.EnableServiceRecovery(recovery => recovery.RestartService(delayInMinutes: 1));
config.EnableShutdown();
config.EnablePauseAndContinue();
config.SetDescription("MyService Desc.");
config.SetDisplayName("MyService");
config.SetServiceName("MyService");
config.RunAsLocalSystem();
});
}
}
} using Topshelf;
using Topshelf.Logging;
namespace MyService
{
public class TestService : ServiceControl
{
static readonly LogWriter _log = HostLogger.Get<TestService>();
public bool Start(HostControl hostControl)
{
_log.Info("TestService Starting...");
return true;
}
public bool Stop(HostControl hostControl)
{
_log.Info("TestService Stopped");
return true;
}
public bool Pause(HostControl hostControl)
{
_log.Info("TestService Paused");
return true;
}
public bool Continue(HostControl hostControl)
{
_log.Info("TestService Continued");
return true;
}
}
}