Calling A COM Component From .NET Windows Service(从 .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 组件
基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
