我正在调用一个外部应用程序,它将 XML 转换为 PDF。
dynamic generator = null;
Assembly a = Assembly.LoadFrom(file);
Type type = a.GetType("Application.ConsoleStartup.Program");
generator = Activator.CreateInstance(type);
接着
generator.Run("testXML.xml");
总的来说,事情是有效的。唯一的问题是,在某个时候新打开的应用程序需要 STA 线程。问题是我无法访问(或非常有限)这个新打开的应用程序。有没有办法绕过这个?请注意,我并不是真正的线程专家。
错误是这样的:
error DCP999: [System.InvalidOperationException] The calling thread must be STA, because many UI components require this.
at System.Windows.Input.InputManager..ctor()
at System.Windows.Input.InputManager.GetCurrentInputManagerImpl()
at System.Windows.Input.InputManager.get_Current()
at System.Windows.Input.KeyboardNavigation..ctor()
at System.Windows.FrameworkElement.FrameworkServices..ctor()
at System.Windows.FrameworkElement.EnsureFrameworkServices()
at System.Windows.FrameworkElement..ctor()
at System.Windows.Controls.Control..ctor()
at System.Windows.Controls.ContentControl..ctor()
at System.Windows.Controls.ToolTip..ctor()
at Application.Parser.Html.Model.Anchor.AfterInsert(IParseContext pc) in C:\work\Common\Main\Source\Parsers\HtmlParser\Model\Anchor.cs:line 31