Excelアドインを起動するとき、次のコードを使用してExcelウィンドウへのハンドルを保持します。
ExcelWindow = new NativeWindow();
ExcelWindow.AssignHandle(new IntPtr(Application.Hwnd));
ハンドルを解放することになると、私はシャットダウンしながらそれをやろうとします:
private void ThisAddInShutdown(object sender, EventArgs e)
{
try
{
ExcelWindow.ReleaseHandle();
}
catch
{
}
}
デバッグモードでExcelを終了すると、すべてが正常に機能します。残念ながら、本番システムでこのコードを実行すると、何が起こっているのかをデバッグする機能がなく、クラッシュします。「ウィンドウがこの問題をチェックしています」ウィンドウが表示され、その後消えます。それだけです。
それほど大したことではありませんが、このようなことでユーザーを困らせたくはありません。それで、誰かがそれが何である可能性があり、私がこれをどのようにデバッグできるかについて何か考えがありますか?ありがとう。