本文介绍了从.NET Windows服务调用COM组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用.NET C#编写的Windows服务,该服务调用COM组件.我也有一个用于测试COM组件的.NET Windows Forms测试应用程序.从测试应用程序可以正常运行.但是,当我在Windows服务中使用相同的代码时,什么也没有发生.COM组件会将所有内容记录到文件中,并且没有生成日志文件的事实提示甚至没有调用COM组件.

I have a Windows Service written in .NET C# which calls a COM component. I also have a .NET Windows Forms test app which I was using to test the COM component. It works fine from the test app. However, when I use the same code in the Windows Service nothing happens. The COM components logs everything to file and the fact the log file doesn't get produced hints that the COM component isn't even being called.

为什么这在我的测试应用程序中有效,但在Windows服务中却不起作用?

Why does this work from my test app but not within the windows service?

推荐答案

服务通常与桌面隔离运行,因此,从服务中调用时,对COM组件的调用与UI隔离.您可以允许"interactWithDesktop "服务参见使用交互式服务.

Service typically run isolated from the desktop, and therefore your call to the COM component is insulated from the UI when called from the service. You may allow a service to "interactWithDesktop" see the section on Using an Interactive Service.

Microsoft(以其无限的智慧)决定将此功能从Window vista中删除,并推荐将您的应用程序分为多个部分并使用其他机制来完成您之间的通信用户界面和您的服务.显然,有些人(包括我自己)不同意,但这就是事实……

Microsoft (<sarcasm>in their infinite wisdom</sarcasm>) Decided that this capability would be removed from Window vista and recommend separating your application into multiple parts and using other mechanisms to accomplish communication between your UI and your service. Obviously, some (including myself) don't agree, but, it is what it is...

http://msdn.microsoft.com/en-us/library/ms683502.aspx

http://social.msdn.microsoft.com/Forums/zh-CN/vbgeneral/thread/e50d8819-d628-48e2-aa2c-6ac6de8380d9/

这篇关于从.NET Windows服务调用COM组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 07:35