如何使用.NET应用程序在Windows服务中调用方法 [英] How to call a method in windows service using .NET application

查看:133
本文介绍了如何使用.NET应用程序在Windows服务中调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Windows服务中调用一个方法,它有一个计时器来安排一些任务。如何在控制台应用程序或asp.net应用程序中调用该方法



我尝试了什么:



i需要在Windows服务中调用一个方法,它有一个计时器来安排一些任务。我怎么样在控制台应用程序或asp.net应用程序中调用该方法

i need to call a method in windows service which have a timer to schedule some task .How will I call that method in a console application or asp.net application

What I have tried:

i need to call a method in windows service which have a timer to schedule some task .How will I call that method in a console application or asp.net application

推荐答案

我不确定我知道你在找什么...你可以: -



a)使用ServiceController.ExecuteCommand向Windows服务程序发送'自定义命令'



I'm not sure I know what you're looking for ... you can :-

a) send a 'Custom command' to a Windows Service Program using ServiceController.ExecuteCommand

const int DoSomething = 666;

service.ExecuteCommand(DoSomething);
service.WaitForStatus(ServiceControllerStatus.Running, timeout);





这可以在外部控制台模式程序中完成。服务实现/覆盖ServiceBase.OnCustomCommand做出反应..





This can be done in an external eg Console mode program. The Service implements/overrides ServiceBase.OnCustomCommand to react ..

protected override void OnCustomCommand(int command)
{
    if (command == DoSomething)
    {
        // ...
    }
}





b)在您的服务中有一个接收器(命名管道,tcp / ip),它从外部源接收消息并执行类似处理'任务'的事情



c)您可以使用Quartz.Net构建一个服务,例如运行任务,使用各种调度规范,例如cron类型规格



但是,正如你写的那样,不,你不能'在Windows服务中调用方法' - 也许你需要更新你的问题并进一步细化您的要求



b) have a 'receiver' (named pipes, tcp/ip) in your service that receives a 'message' from an external source and does something like process a 'task'

c) you can have a Service built with Quartz.Net for example that runs 'tasks', by using all sorts of scheduling specs, eg cron type specs

but, as you have written it, no, you cannot 'call a method in windows service' - maybe you need to update your question and refine your requirements a touch more


这篇关于如何使用.NET应用程序在Windows服务中调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆