OpenFileDialog window 未显示

OpenFileDialog window not showing

我对来自 Windows Forms 的 OpenFileDialog 有问题(如果我在控制台应用程序、win 窗体或 wpf 中使用它并不重要)(C#)。

我有一个带有按钮的小型测试项目,当按下该按钮时,将要求用户select 图像(使用 OpenFileDialog)并将其路径发送到处理方法。 process 方法在 c++ 本机代码中,并使用 c++ cli (CLR) 访问。该方法向网络服务发送请求并等待响应(网络服务是本地的,所以响应速度很快)。

问题是这样的:如果我按下按钮 2 次(select 一张图像 + 处理,完成后我处理另一张图像),第 3 次 window 将不会显示,它卡在 ShowDialog 上。

如果我从 WPF 运行 它给我这个错误:

DisconnectedContext occurred Message: Managed Debugging Assistant 'DisconnectedContext' has detected a problem in 'd:\Project\WpfApplication1.vshost.exe'.

Additional information: Transition into COM context 0x1b09d5d0 for this RuntimeCallableWrapper failed with the following error: The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED)). This is typically because the COM context 0x1b09d5d0 where this RuntimeCallableWrapper was created has been disconnected or it is busy doing something else and cannot process the context transition. No proxy will be used to service the request on the COM component and calls will be made to the COM component directly. This may cause corruption or data loss. To avoid this problem, please ensure that all COM contexts/apartments/threads stay alive and are available for context transition, until the application is completely done with the RuntimeCallableWrappers that represents COM components that live inside them.

知道如何解决这个问题或者它意味着什么吗?

我发现了问题(不是来自网络服务通信):在我的本机代码中的某个地方,我正在取消初始化 COM,但是 .NET UI 需要 COM 启动并且 运行。

所以我所要做的就是从我的本机代码中删除 COM 的单元化。