Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
573 views
in Technique[技术] by (71.8m points)

c# - How to debug hanging SaveFileDialog

Several users of my VSTO add-ins report hangs that occur when a "Save as" dialog should be displayed. This happens with an Excel add-in as well as a Word add-in. Interestingly, both applications also tend to hang when invoking the "Save as" command on a document.

I am having a hard time to troubleshoot this because the entire application just freezes after

// using System.Windows.Forms;
SaveFileDialog dlg = new SaveFileDialog();
// lines to configure dlg left out
dlg.ShowDialog();

When attempting to close Excel or Word in this situation, a message box "Excel/Word can not be closed" appears, and people have to resort to the Task Manager to get rid of it.

The fact that both Excel and Word frequently hang on "Save as" is particularly disturbing, because I don't see how my add-ins interfere with the built-in "Save as" commands of these applications.

To make matters worse, the add-ins need not even be loaded. Deactivating them by unchecking the corresponding entry in "COM add-ins" and restarting the application does not solve the problem. I have to completely remove the add-ins to make sure "Save as" does not freeze the application.

This makes me think that it is not code in my add-ins that is the problem, but the mere presence of an (inactive) VSTO add-in that prevents a file dialog from appearing, thereby causing a hang.

The hangs do not always occur, and not on all machines. It's quite random.

How would I go about investigating this further? I have Visual Studio Professional 2013, but do not know how to find out why and where the Office application freeze.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Excel freezes on Open/Save As if a managed add-in is registered with a "Warmup" registry value, even if the add-in is not even loaded.

The "Warmup" registry value, when set to 1 in an add-in's registry key, was once supposed to cause Excel to load the VSTO runtime at startup, rather than when the first user interaction with the add-in occurred. Apparently, it was never implemented and has since been removed from Microsoft's online documentation of the registry entries for VSTO add-ins.

Once I removed the "Warmup" value from my add-in's registry key, Excel's Open/Save As dialogs no longer froze, nor did the add-in's own SaveFileDialog.ShowDialog() calls. I don't know why this is, but evidently, the "Warmup" value does do something.

I was able to reproduce this with a dummy add-in that does not do anything. If that dummy add-in is registered in HKCUSoftwareMicrosoftExcelAddins without the "Warmup" DWORD, Excel works just fine. As soon as I add the DWORD with a value of 1, Excel freezes when I click Open or Save As -- again, the dummy add-in does not do anything at all.

So, if people get here wondering why their Office application freezes after installation of a VSTO add-in, I'd suggest to remove the "Warmup" value from the registry rather than spending hours debugging their code (as I did before I found out about "Warmup").

Feedback from my users is positive.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...