怎么在Windows Service 里使用 ActiveX

myblind 2006-07-08 11:47:38
我有一个Windows Service,启动的时候会调用 ClassLibrary1.Form1,Form1上有一个ActiveX。
服务使用帐号 Local System,而且允许服务与桌面交互。
但是发生错误,该怎么解决啊:

System.Threading.ThreadStateException: 因为当前线程不在单线程单元中,故无法实例化 ActiveX 控件“b0b25446-7656-456c-8d3c-60a0ac6eac49”。
at System.Windows.Forms.AxHost..ctor(String clsid, Int32 flags)
at System.Windows.Forms.AxHost..ctor(String clsid)
at AxJDSMSCtrl.AxJindiSMSControl..ctor()
at ClassLibrary1.Form1.InitializeComponent()
at ClassLibrary1.Form1..ctor()
at WindowsService1.Service1.OnStart(String[] args)
...全文
234 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2006-07-10
  • 打赏
  • 举报
回复
[STAThread]
static void Main()
{
................
}
bj_niuniu 2006-07-10
  • 打赏
  • 举报
回复
看不到你的代码,怎么能知道错误在哪里?
myblind 2006-07-10
  • 打赏
  • 举报
回复
jiangsheng(蒋晟.Net[MVP]) 您说什么呢?

我也用Administrator的帐号试过了,同样的错误,
"因为当前线程不在单线程单元中,故无法实例化 ActiveX 控件"
我是个developer,上述原因都不可能存在

因为同样的程序 WinForm 就能运行
蒋晟 2006-07-09
  • 打赏
  • 举报
回复
Check following things on production server
1. On What login credentials this service is running ?
2. This user has sufficient previlages to access resources , if not try changing the user accounts?
3. Is this service making calls to other assemblies dynamically or other COM Dlls dynamically if so make sure these assemblies exist at proper path and Com Dlls are registered.
4 OnStart has to terminate in 30 seconds or service manager shuts down the service. It's possible that CLR cannot be loaded up timely.
Knight94 2006-07-08
  • 打赏
  • 举报
回复
你应该把form做成一个单独的app,然后用它与service进行交互,做在service中是一个不明智的做法。
myblind 2006-07-08
  • 打赏
  • 举报
回复
o, 换句话说也就是 这个用 Windows Service 无法实现喽?
Knight94 2006-07-08
  • 打赏
  • 举报
回复
to 这个 Service 要求串口通讯,而这个功能是一个第三方的 ActiveX 提供的,

建议你用service改成app。
myblind 2006-07-08
  • 打赏
  • 举报
回复
即使不用 Form,我的 Service 也会出错。
这个 Service 要求串口通讯,而这个功能是一个第三方的 ActiveX 提供的,
所以 Service 必须调用这个 OCX

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧