Tag: topshelf

Topshelf在VS2010中托管应用程序调试

我正在尝试使用Topshelf托管应用程序Topshelf.Host.exe来执行我的.NET类库作为Windows服务。 http://topshelf-project.com/documentation/shelving/ 我在连接VS2010内部的调试器时遇到了麻烦。 这是我的设置 Topshelf.Host.exe在c:\ projects中说 我的classlibrary服务构建到c:\ projects \ Services \ library-name \ 运行Topshelf.Host.exe作为类库的外部应用程序进行调试 使用F5 /运行Topshelf.Host.exe正在运行,但它似乎没有拿起并加载我的类库。 有任何想法或更好的方法来设置调试?

Topshelf – 基于自定义参数启动线程

我做了一个使用自定义参数的topshelf webservice: string department = null; // *********************Below is a TopShelf code*****************************// HostFactory.Run(hostConfigurator => { hostConfigurator.AddCommandLineDefinition(“department”, f => { department = f; }); //Define new parameter hostConfigurator.ApplyCommandLine(); //apply it Helpers.LogFile(“xxx”, “Got department:”+department); hostConfigurator.Service(serviceConfigurator => { serviceConfigurator.ConstructUsing(() => new MyService(department)); //what service we are using serviceConfigurator.WhenStarted(myService => myService.Start()); //what to run on start serviceConfigurator.WhenStopped(myService => myService.Stop()); […]

Windows服务已启动,然后使用Topshelf停止

我正在使用Quartz.net,我试图让Quartz服务器在Windows服务中启动。 我创建了一个Windows服务项目并包含了Quartz.net库。 在我的服务类中,我有: protected override void OnStart(string[] args) { try { Host host = HostFactory.New(x => { x.Service(s => { s.SetServiceName(“quartz.server”); s.ConstructUsing(builder => { QuartzServer server = new QuartzServer(); server.Initialize(); return server; }); s.WhenStarted(server => server.Start()); s.WhenPaused(server => server.Pause()); s.WhenContinued(server => server.Resume()); s.WhenStopped(server => server.Stop()); }); x.RunAsLocalService(); //x.RunAs(@”mydomain\mysusername”, “mypassword”); x.SetDescription(Configuration.ServiceDescription); x.SetDisplayName(Configuration.ServiceDisplayName); x.SetServiceName(Configuration.ServiceName); }); host.Run(); } […]

如何强制quartz.net作业在完成后重新启动intervall

我有一个项目,我使用TopShelf和TopShelf.Quartz 按照这个例子,我正在建立我的工作 s.ScheduleQuartzJob(q => q.WithJob(() => JobBuilder.Create().Build()) .AddTrigger(() => TriggerBuilder.Create() .WithSimpleSchedule(builder => builder .WithIntervalInSeconds(5) .RepeatForever()) .Build()) ); 即使前一个仍然在运行,它每隔五秒就会激活一次。 我真正想要的是开始一份工作,并在完成后等待五秒钟然后重新开始。 这是可能的还是我必须实现自己的逻辑(例如通过静态变量)。

如何捕获exception并停止Topshelf服务?

我有一个topshelf Windows服务,我想做一些检查(即如果存在xml文件),如果检查失败,我需要Windows服务停止。 所以我尝试在Start()方法中进行检查,然后引发exception: public void Start() { if (!File.Exists(_xmlFile) throw new FileNotFoundException(); // Do some work here if xml file exists. } 但是,在exception之后,Windows服务仍然作为一个进程保留,然后我必须在任务管理器中手动终止。 如果某些条件(即未找到文件)成立,是否有办法不运行服务?

Windows服务中的Console.WriteLine()?

我目前正在使用TopShelf和控制台应用程序来创建Windows服务。 当我将代码作为控制台应用程序运行时,我使用一些Console.WriteLine()来输出结果。 一旦代码执行了它应该执行的操作,我将控制台应用程序安装为Windows服务。 即使Windows服务无法写入控制台,离开Console.WriteLine()代码是否有任何缺点? 如果我将Console.WriteLine()留在那里,是否存在代码不稳定的风险?

如何使用TopShelf无法识别的CommandLine参数?

我想在安装时将一些自定义参数传递给控制台应用程序,并通过TopShelf将其作为Windows服务启动。 我用的时候: MyService install start /fooBar: Test 控制台应用失败: [Failure]命令行找到了一个未知的命令行选项:DEFINE:fooBar = Test 题: 如何让我的参数被TopShelf识别,以便我可以消耗它们的值?