从 .NET Windows 服务调用 COM 组件

Calling A COM Component From .NET Windows Service(从 .NET Windows 服务调用 COM 组件)

本文介绍了从 .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 是隔离的.您可以允许服务与桌面交互"参见使用互动服务.

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(<sarcasm>in their无穷的智慧</sarcasm>)决定从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/en-US/vbgeneral/thread/e50d8819-d628-48e2-aa2c-6ac6de8380d9/

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

本文标题为:从 .NET Windows 服务调用 COM 组件

基础教程推荐