在CLR已经无法从COM上下文转换[...] 60秒 [英] The CLR has been unable to transition from COM context [...] for 60 seconds

查看:1952
本文介绍了在CLR已经无法从COM上下文转换[...] 60秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到的code是用来工作这个错误。我并没有改变的code。

I am getting this error on code that used to work. I have not changed the code.

下面是完整的错误:

在CLR已经无法从COM上下文0x3322d98过渡到COM环境0x3322f08 60秒。拥有目标上下文/公寓线程是最有可能要么做一个非抽水等待或处理一个很长的运行操作,不抽水Windows消息。这种情况一般具有性能产生负面影响,甚至可能导致应用程序变得无响应或内存使用情况不断积累随着时间的推移。为了避免这个问题,所有单线程单元(STA)线程应该使用抽水等待基元(如CoWaitForMultipleHandles),并在长时间运行的操作常规泵的消息。

The CLR has been unable to transition from COM context 0x3322d98 to COM context 0x3322f08 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

在这里,是导致它的code:

And here is the code that caused it:

var openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
openFileDialog1.DefaultExt = "mdb";
openFileDialog1.Filter = "Management Database (manage.mdb)|manage.mdb";

//Stalls indefinitely on the following line, then gives the CLR error
//one minute later.  The dialog never opens.
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
    ....
}

是的,我相信对话是不是在后台打开,没有,我也没有任何明确的COM code或不受管理的编组和多线程。

Yes, I am sure the dialog is not open in the background, and no, I don't have any explicit COM code or unmanaged marshalling or multithreading.

我不知道为什么打开文件对话框无法打开 - ?任何想法

I have no idea why the OpenFileDialog won't open - any ideas?

推荐答案

想通了 - 它会自动把你带到你看,在对话框中打开每一次的最后位置。如果该位置是不存在的网络位置(例如,其他计算机是关闭的),它只是挂永远。

Figured it out - it automatically brings you to the last location you looked in every time the dialog opens. If that location is a network location that no longer exists (ex. the other computer is off), it will just hang forever.

我的解决方法是这样的:

My workaround looks like this:

string initialDirectory = ...; //Figure out an initial directory from somewhere
openFileDialog1.InitialDirectory = !Directory.Exists(initialDirectory)
                                       ? Path.GetPathRoot(Environment.SystemDirectory)
                                       : initialDirectory;

这篇关于在CLR已经无法从COM上下文转换[...] 60秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆