简体   繁体   English

显示 OpenFileDialog 有时会导致应用程序挂起

[英]Showing an OpenFileDialog occasionally causes the application to hang

Most of the time, the OpenFileDialog is displayed with no issue, but on rare occasions, showing it causes the application to hang indefintely until the process is ended.大多数时候,OpenFileDialog 显示没有问题,但在极少数情况下,显示它会导致应用程序无限期挂起,直到进程结束。

The OpenFileDialog is defined as below: OpenFileDialog 定义如下:

        var dialog = new OpenFileDialog
        {
            ValidateNames = false,
            CheckFileExists = false,
            CheckPathExists = true,
            FileName = "This Folder",
        };
        if (dialog.ShowDialog() == DialogResult.OK)
        {
            //logic here
        }

Answers to similar questions suggest that the problem may be related to the DLLs my application is using.对类似问题的回答表明该问题可能与我的应用程序正在使用的 DLL 有关。

Possibly relevant debug output of a successful run follows:成功运行的可能相关调试 output 如下:

Whenever the program is launched:每当启动程序时:

...
'Program Name.exe' (Win32): Loaded 'C:\Windows\SysWOW64\iertutil.dll'. 
'Program Name.exe' (Win32): Loaded 'C:\Windows\SysWOW64\propsys.dll'. 
Exception thrown at 0x74EC3572 in Program Name.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x00B3D034.
Exception thrown at 0x74EC3572 in Program Name.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
Exception thrown at 0x74EC3572 in Program Name.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
'Program Name.exe' (CLR v4.0.30319: Program Name.exe): Loaded 'Microsoft.GeneratedCode'. 
'Program Name.exe' (Win32): Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\Microsoft.V9921e851#\10e86f631668518a182dfda3901d1848\Microsoft.VisualBasic.ni.dll'. 
...

The first time that the OpenFileDialog is shown within a program run: OpenFileDialog 第一次在程序运行中显示:

...
'Program Name.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sxs.dll'. 
mincore\com\oleaut32\dispatch\ups.cpp(2125)\OLEAUT32.dll!77444221: (caller: 77444318) ReturnHr(1) tid(7cb0) 8002801D Library not registered.
'Program Name.exe' (Win32): Loaded 'C:\Windows\SysWOW64\StructuredQuery.dll'. 
...
'Program Name.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140.dll'. 
'Program Name.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140.dll'. 
Exception thrown at 0x74EC3572 in Program Name.exe: Microsoft C++ exception: Mso::RegistryException at memory location 0x0B15C968.
Exception thrown at 0x74EC3572 in Program Name.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
'Program Name.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msi.dll'. 
...

As opening the OpenFileDialog causes the application hang only rarely, I do not have any debug output for such a run.由于打开 OpenFileDialog 很少会导致应用程序挂起,因此我没有针对此类运行的任何调试 output。

None of the above exceptions are present when I run the application in its CLI mode.当我在其 CLI 模式下运行应用程序时,不存在上述异常。

I have tried researching the above exception messages, but this has not led me to a solution.我曾尝试研究上述异常消息,但这并没有让我找到解决方案。

Do you know what might be causing this issue?你知道什么可能导致这个问题吗?

Do you have any suggestions on how I might proceed with debugging the problem?您对我如何继续调试问题有什么建议吗?

That happened to me too.这也发生在我身上。 It happened because the form that was calling openFileDialog was created in a different thread, but i still dont know why it happens.发生这种情况是因为调用 openFileDialog 的表单是在不同的线程中创建的,但我仍然不知道它为什么会发生。 A possible workaroud is:一种可能的解决方法是:

    var dialog = new OpenFileDialog
    {
        ValidateNames = false,
        CheckFileExists = false,
        CheckPathExists = true,
        FileName = "This Folder",
    };
    this.Hide();
    if (dialog.ShowDialog() == DialogResult.OK)
    {
        //logic here
    }
    this.Show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM