topshelf

ASP.NET Core使用TopShelf部署Windows服务

有些话、适合烂在心里 提交于 2020-08-16 10:00:48
asp.net core很大的方便了跨平台的开发者,linux的开发者可以使用apache和nginx来做反向代理,windows上可以用IIS进行反向代理。 反向代理可以提供很多特性,固然很好。但是还有复杂性,我们也可以使用windows service来直接启动kestrel。 asp.net core官方网站提供了一种基于windows服务部署的方法: 在 Windows 服务中托管 ASP.NET Core 这种方式需要修改代码,然后部署的时候,使用命令行创建、安装服务,然后再启动。 感觉还是不够爽快,我们可以使用topshelf改造一下。 TopShelf topshelf可以很便捷地将一个windows console程序改造成windows service,只需要稍微修改一下代码结构,然后通过nuget包就可以简单操作了。安装与部署也是 极其 方便,而且,topshelf在调试的时候,直接是作为console程序,极其便于调试。 TopShelf项目地址: http://topshelf-project.com/ 步骤 首先引用nuget包: Install-Package TopShelf 然后改造一下program.cs public class Program { public static void Main(string[] args) { var rc =

C#之TopShelf启动Windows服务 原文链接:https://blog.csdn.net/qq_36664495/java/article/details/90600995

倾然丶 夕夏残阳落幕 提交于 2020-08-13 18:15:05
1、项目的主要运行代码 HostFactory.Run(x => { x.RunAsLocalSystem(); x.SetDescription("topshelf测试"); x.SetDisplayName("topshelftest"); x.SetServiceName("topshelftest"); x.Service<TopshelfTest>(s => { s.ConstructUsing(name => new TopshelfTest()); s.WhenStarted(tc => tc.Start()); s.WhenStopped(tc => tc.Stop()); }); }); using System; using System.Timers; namespace TopshelfDemo { public class TopshelfTest { readonly Timer timer; public TopshelfTest() { timer = new Timer(1000) { AutoReset = true }; timer.Elapsed += (sender, eventArgs) => { Run(); }; } public void Start() { timer.Start(); } public void Stop() {

VS Installer Projects - Perform some code after installation

旧时模样 提交于 2020-06-16 19:18:51
问题 I have Visual Studio 2017 and just added the Microsoft Visual Studio Installer Projects extension. The project I want to add to the installer is a Windows Service application build by Topshelf . To manually install the Windows Service, I open a CMD window as admin and run a command in the application folder (eg. bin/debug) to install the Windows Service app. Issue Now, I know for sure that the installer has no convenient feature to install the Service, as the only thing it does (in simple

VS Installer Projects - Perform some code after installation

谁都会走 提交于 2020-06-16 19:18:49
问题 I have Visual Studio 2017 and just added the Microsoft Visual Studio Installer Projects extension. The project I want to add to the installer is a Windows Service application build by Topshelf . To manually install the Windows Service, I open a CMD window as admin and run a command in the application folder (eg. bin/debug) to install the Windows Service app. Issue Now, I know for sure that the installer has no convenient feature to install the Service, as the only thing it does (in simple

Windows服务 System.ServiceProcess.ServiceBase类

邮差的信 提交于 2020-05-08 09:30:59
一、Windows服务 1、Windows服务应用程序是一种需要长期运行的应用程序,它适合服务器环境。 2、无用户界面,任何消息都会写进Windows事件日志。 3、随计算机启动而启动,不需要用户一定登录Windows。 4、通过服务控制管理器,可以终止、暂停及当需要时启动Windows服务。 二、体系结构 System.ServiceProcess命令空间 1、类继承关系: Object Component ServiceBase ServiceController Installer ComponentInstaller ServiceInstaller ServiceProcessInstaller 2、体系结构 第一部分就是服务程序。 实现系统的业务需求。 Service Control Manager(SCM)。SCM是操作系统的一个组成部分(services.exe),作用是于服务进行通信。 SCM包含一个储存着已安装的服务和驱动程序的信息的数据库,通过SCM可以统一的、安全的管理这些信息。 一个服务拥有能从SCM收到信号和命令所必需的的特殊代码,并且能够在处理后将它的状态回传给SCM。 ServiceBase:(服务程序)实现系统的业务需求。 在创建新的服务类时,必须从 ServiceBase 派生。 第二部分服务控制程序, 是一个Service Control

WTSSendMessage don't show messagebox on remote desktop

早过忘川 提交于 2020-02-25 13:41:27
问题 I have a Windows service application that displays a confirm popup for further action. It works fine when I install the service application on my local machine, but when I install it on the remote machine, the confirm popup is not getting displayed. [DllImport("Kernel32.dll", SetLastError = true)] static extern int WTSGetActiveConsoleSessionId(); public static IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero; public static int ConfirmPopup(string message, string title) { try { WTSSendMessage

How do I force a quartz.net job to restart intervall after completion

≡放荡痞女 提交于 2020-01-30 06:27:46
问题 I have a project where I use TopShelf and TopShelf.Quartz Following this example I am building my jobs with s.ScheduleQuartzJob(q => q.WithJob(() => JobBuilder.Create<MyJob>().Build()) .AddTrigger(() => TriggerBuilder.Create() .WithSimpleSchedule(builder => builder .WithIntervalInSeconds(5) .RepeatForever()) .Build()) ); which fires my job every five seconds even if the previous is still running. What I really want to achive is to start a job and after the completion wait five seconds and

Wix installer based TopShelf windows service fails to start

我怕爱的太早我们不能终老 提交于 2020-01-24 18:48:45
问题 I have written a bare-bones .NET 4.7.2 C# Windows Service using TopShelf and Quartz. The service works when I debug it using Visual Studio 2019 on my Windows 10 laptop. I then created a Wix 3.11.2 based setup to install and start this service. Now, I am trying to install the service on my laptop using this installer. The installer is able to copy the files but fails to start the service. Here is the code: Product.wxs <?xml version="1.0" encoding="UTF-8"?> <Wix xmlns="http://schemas.microsoft

Windows Service started and then stopped using Topshelf

南楼画角 提交于 2020-01-22 20:29:16
问题 I am using Quartz.net and I am trying to get the Quartz server to start-off in a Windows Service. I have created a Windows Service Project and included the Quartz.net libraries. In my Service class I have: protected override void OnStart(string[] args) { try { Host host = HostFactory.New(x => { x.Service<IQuartzServer>(s => { s.SetServiceName("quartz.server"); s.ConstructUsing(builder => { QuartzServer server = new QuartzServer(); server.Initialize(); return server; }); s.WhenStarted(server =

Serilog in Windows-Service not writing to logfile

ぐ巨炮叔叔 提交于 2020-01-13 07:32:09
问题 I am using Serilog within an TopShelf Service, logging to the console and a rolling file. When running the service in a console my messages are written to the logfile, but when I install the service and run it no logging occurs. Is there anything special I need to configure? The file is written to the binaries folder under ".\logs\log-{date}.txt". Best regards Gope 回答1: I had a very similar issue. In my case the problem was with relative paths. I just had to specify absolute path. Now it