0

さて、プレゼンターによって制御される、ロジックがほとんどない非常に単純なフォームがあります。フォームを初期状態にリセットするメソッド public void Reset() があります。これは、プレゼンターのみが、非常に特殊なケース (アクティビティ タイムアウトなど) で呼び出す必要があります。問題が発生していますが、いくつかのエッジケース (たとえば、アプリケーションがデータベース接続を失うことをシミュレートしている場合) で、Reset() メソッドが呼び出されるべきではないときに呼び出され、何が原因であるかを理解できません。 .

そこで、Reset() メソッドにトレースポイントを設定し、コールスタックを出力させました。奇妙なことに、さらに多くの疑問が生じました。Reset() への呼び出しがどこから来ているのかを理解するのを手伝ってくれる人はいますか? 私のコールスタックは以下です。

説明しなければならないことの 1 つは、コールスタックで確認できる DriverInterface2.UI.WinForms.NonInheritingForms.CheckInForm です。これは、ICheckInForm (関連するインターフェイス) の非常に単純な実装であり、単純に CheckInForm を作成し、それに委任します。これは、Castle Windsor を使用していて、Form から継承するクラスを配線するのが面倒だからです。いずれにせよ、そのメソッドの完全な内容は次のとおりです。

public void Reset() {_form.Reset();}

そして、コールスタックは次のとおりです。

Function: DriverInterface2.UI.WinForms.CheckInForm.Reset(), 
Thread: 0xA96F4 Main Thread, 
Caller: DriverInterface2.UI.WinForms.NonInheritingForms.CheckInForm.Reset, 
Callstack:  DriverInterface2.UI.WinForms.dll!DriverInterface2.UI.WinForms.CheckInForm.Reset
    DriverInterface2.UI.WinForms.dll!DriverInterface2.UI.WinForms.NonInheritingForms.CheckInForm.Reset
    [Native to Managed Transition]
    [Managed to Native Transition]
    mscorlib.dll!System.Delegate.DynamicInvokeImpl
    System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackDo
    System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackHelper
    mscorlib.dll!System.Threading.ExecutionContext.runTryCode
    [Native to Managed Transition]
    [Managed to Native Transition]
    mscorlib.dll!System.Threading.ExecutionContext.RunInternal
    mscorlib.dll!System.Threading.ExecutionContext.Run
    System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallback
    System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbacks
    System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc
    System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc
    System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WndProc
    System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc
    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage
    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc
    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback
    [Native to Managed Transition]
    [Managed to Native Transition]
    System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop
    System.Windows.Forms.dll!System.Windows.Forms.Application.Run
    DriverInterface2.exe!DriverInterfaceRunner.Program.Main
    [Native to Managed Transition]
    [Managed to Native Transition]
    mscorlib.dll!System.AppDomain.ExecuteAssembly
    Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly
    mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context
    mscorlib.dll!System.Threading.ExecutionContext.Run
    mscorlib.dll!System.Threading.ThreadHelper.ThreadStart
4

1 に答える 1

1

Windows メッセージが .NET イベントにマーシャリングされ、そのイベントが Reset メソッドを呼び出しているように見えます。どのイベントかはわかりません。イベントでない場合は、非同期デリゲートである可能性があります。

Reset メソッドが Application.Idle イベントから呼び出されている場合は、それが原因である可能性があります。

非同期デリゲートを発生させた呼び出し (イベント ハンドラーまたはその他) は、呼び出しが非同期であるため、スタックに表示されません。したがって、システムが Windows メッセージ ポンプを介してデリゲートをディスパッチする前に、スタックがその呼び出しから解放される場合があります。したがって、元の呼び出し元はスタックに存在しなくなります。

于 2008-12-18T18:21:22.723 に答える