我有一个 .NET 类,它公开了两种公共方法:一种用于创建 InfoPath 表单,另一种用于导出为一种受支持的格式。我正在使用 Microsoft FormControl 来执行此操作。它由不显示的表单托管。我被 Winforms 应用程序调用,但在 MTA 工作线程而不是 UI 线程上调用。所以我创建了一个 STA 线程并在其上执行,它只工作一次,然后导致这个异常:
System.InvalidOperationException 未处理 Message="无法获取 'FormControl' 控件的窗口句柄。不支持无窗口 ActiveX 控件。" Source="System.Windows.Forms" StackTrace:在 System.Windows.Forms.AxHost.InPlaceActivate() 在 System.Windows.Forms.AxHost.TransitionUpTo(Int32 state) 在 System.Windows.Forms.AxHost.EnsureWindowPresent() System.Windows.Forms.AxHost.CreateHandle() 在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) 在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) 在 System.Windows.Forms.AxHost.EndInit( ) 在 C:\Windows\Temp\InfoPathCreateStaThreadTest\InfoPathCreateStaThreadTest\FormControlHost.Designer.cs 中的 InfoPathCreateStaThreadTest.FormControlHost.InitializeComponent():
经过一些试验,我开始怀疑这是一个消息泵送问题。然后我遇到了这个,这让我更加怀疑:http: //blogs.msdn.com/cbrumme/archive/2004/02/02/66219.aspx
我尝试了各种发送消息的方法,但都没有成功。我应该提到自动化 InfoPath 应用程序的替代方案是不可行的,除非我能弄清楚如何隐藏该应用程序。
任何帮助将非常感激。