困扰了我N久的一个问题。

goonfighting 2009-09-25 03:15:22
软件中使用了第三方控件AxSunExcelControl,在编译的时候在
this.axSunExcelControl2 = new AxSUNEXCELCONTROLLib.AxSunExcelControl();出错并提示“当前线程不在单线程单元中,因此无法实例化 ActiveX 控件“54454800-24d7-47e5-ab81-f06a6bbaa94f””,在网上找了N个办法都不管用,特来求救。我在调用一个子窗体的时候将this传给了该子窗体,是这个原因导致的吗?
...全文
161 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
woaijingyun 2009-09-25
  • 打赏
  • 举报
回复
帮顶
快40的码农 2009-09-25
  • 打赏
  • 举报
回复
帮顶
lzsh0622 2009-09-25
  • 打赏
  • 举报
回复
还可以用,系统推荐实用新版本的
goonfighting 2009-09-25
  • 打赏
  • 举报
回复
Thread.CurrentThread.ApartmentState 已过时是什么意思啊?
goonfighting 2009-09-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jzywh 的回复:]
Thread.CurrentThread.ApartmentState = ApartmentState.STA;

this.axSunExcelControl2 = new AxSUNEXCELCONTROLLib.AxSunExcelControl();
[/Quote]
加上之后Thread.CurrentThread.ApartmentState 有个绿色的下划线,提示用SetApartmentState 代替等。
liujintaozyc 2009-09-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jzywh 的回复:]
Thread.CurrentThread.ApartmentState = ApartmentState.STA;

this.axSunExcelControl2 = new AxSUNEXCELCONTROLLib.AxSunExcelControl();
[/Quote]
jzywh 2009-09-25
  • 打赏
  • 举报
回复
Thread.CurrentThread.ApartmentState = ApartmentState.STA;

this.axSunExcelControl2 = new AxSUNEXCELCONTROLLib.AxSunExcelControl();
threenewbee 2009-09-25
  • 打赏
  • 举报
回复
如果你有那个ActiveX的源代码,用单线程编译下。
lzsh0622 2009-09-25
  • 打赏
  • 举报
回复
把[STAThread] 加到Main的上一行

[STAThread]
static void Main(string[] args)

110,533

社区成员

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

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

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