C# - 在新进程中执行静态方法
我需要帮助异步执行静态方法以及在其自己的进程中,这样即使启动此执行的客户端应用程序已关闭,该方法也将继续执行。
执行此操作的一种选择是创建一个控制台应用程序并将该控制台应用程序作为新进程执行。但是,我在想是否有人对这个问题有不同的解决方案。
提前致谢。
问候, 维拉斯
I wanted a help in executing a static method asynchronously as well as in it's own process so that even if the client application that kicked-off this execution is closed, the method will continue it's execution.
One option to do this is create a console application and execute this console application as a new process. However, I was thinking if anyone has a different solution to this problem.
Thanks in advance.
Regards,
Vilas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我理解你的问题是正确的,最好选择 .Net 中的 Windows 服务和远程处理。服务启动后,您可以从任何 Remoting 客户端发起对该方法的调用。
If I understand your problem right, it is better to go for Windows Service and Remoting in .Net. You can initiate the call to the method from any Remoting client once the service is started.
我同意 srikanthv 关于 Windows 服务的观点,但我个人会使用 MSMQ 与其进行通信。
I agree with srikanthv about a Windows Service, but I'd personally use the MSMQ to communicate with it.
如果静态方法需要与客户端在同一台机器上,并且您无法在该机器上安装服务,那么您始终可以在客户端上设置一个标志来指示该方法正在运行,并且如果客户端在该方法运行时关闭设置标志后,中止关闭并隐藏表单,直到方法完成,然后正常关闭。
If the static method needs to be on the same machine as the client and you can't install services on the machine, you could always set a flag on the client to indicate that the method is running, and if the client is closed while the flag is set, abort the close and just hide the form until the method completes, then close gracefully.