我打電話給外部應用程序,它將XML轉換爲PDF。System.Activator.CreateInstance和線程
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
我試過了,它也是這樣做的,但我也需要來自應用程序的一些資源(如輸出路徑以打開此PDF)。 – 2013-04-26 07:59:33
那麼,最後我仍然使用這個,它工作正常。謝謝 – 2013-04-26 08:14:48
嘗試使用參數屬性。此屬性的內容將顯示爲您的其他進程的主要功能的參數。 – 2013-04-26 08:48:37