如何从运行Windows服务的方法调用 [英] How to call method from running windows service
问题描述
我已经使用c#2005创建并启动了Windows服务Service1(exe作为MyService.exe)。
我包含了一个GetMyRandomNumber()方法,该方法返回一个随机双精度值。
I have created and started windows service Service1 (with exe as MyService.exe) using c# 2005. . I have included a method GetMyRandomNumber() that returns a random double value.
这里的问题是如何使用此运行服务以及如何调用
The problem here is how could use this running service and how could i call the method.
我尝试添加MyService.exe的引用,并以-
I have tried adding reference of MyService.exe and access the method as -
Service1 s = new Service1();
MessageBox.Show(s.GetMyRandomNumber().ToString());
但是发现未从服务的运行实例中调用该方法,即使我停止了
But found that the method is not called from the running instance of the service i.e. even though i stop the service the statements are executed.
有人可以向我解释如何从运行服务的实例中调用该方法。
Could someone explain me how can I call the method from running instance of the service.
感谢您分享宝贵的时间。
Thanks for sharing your valuable time.
推荐答案
您应该看看Remoting
You should have a look at Remoting
- 在C#中进行远程处理(不再提供链接)
- 如何在
Windows服务应用程序中托管.NET远程处理对象 - 如何使用.Net远程处理使用(不再提供链接)
- 。NET
远程处理的简单介绍
- Remoting in C# (Link no Longer available)
- How To Host .NET Remoting Objects in Windows Service Application
- How to Use .Net Remoting Using (Link no Longer available)
- A Simple Introduction to .NET Remoting
这篇关于如何从运行Windows服务的方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!