好的,所以我有一个非常简单的表单,其中几乎没有逻辑,由演示者控制。有一个方法 public void Reset() 将表单重置为其初始状态。这应该只由演示者调用,并且在非常特殊的情况下(例如活动超时)。我遇到了一个问题,尽管在一些边缘情况下(例如,当我模拟我的应用程序失去数据库连接时) Reset() 方法在不应该被调用的时候被调用,我无法弄清楚是什么.
所以我在 Reset() 方法中设置了一个跟踪点并让它打印调用堆栈。奇怪的是,这引发了更多的问题。谁能帮我弄清楚对 Reset() 的调用来自哪里?我的调用堆栈在下面。
我应该解释的一件事是 DriverInterface2.UI.WinForms.NonInheritingForms.CheckInForm 您可以在调用堆栈中看到。这是 ICheckInForm(相关接口)的一个非常简单的实现,只需创建 CheckInForm 并将其委托给它。它存在只是因为我使用的是城堡温莎,并且连接从 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