有一个很复杂的应用程序,有许多.NET和Native DLL
Main_App.exe
是Windows窗体应用。在其MainForm_Load()
中,加载一个Native(ATL)COM DLL类,调用它,在FinalConstruct()
加载并通过COM调用另一个.NET dll,并尝试显示一个Form。
public void ShowXXXXDialog()
{
XXXXDialog dlg = new XXXXDialog();
dlg.ShowDialog();
}
立即打开和关闭(约100毫秒后)取消结果 到目前为止我的观察结果:
MsgBox.Show(".....")
之前添加dlg.ShowDialog()
,则可以正常使用。dlg.ShowDialog();
(两次),第二次就可以了。ShowXXXXDialog
,它可以正常工作。基于这些观察,我的感觉是,在ShowXXXXDialog()
启动期间调用Main_App.exe
时,MainForm_Load()
尚未完成,似乎某些内容未在.NET中正确初始化表格?
因此,呼叫dlg.ShowDialog()
将立即打开和关闭。但是,它可能会完成.NET Forms初始化,因为再次调用dlg.ShowDialog()
将适用于第二次调用。 (或显示一个msgbox也将解决...见第2点))
我在[{1}}中加了一个断点,但我没有看到任何特别的东西。 callstack:
XXXXDialog.FormClosing()
你可以在其中看到,.NET启动 - >原生电话 - > .NET lib调用 - >打开表单 - >关闭表格。
到目前为止,我不知道为什么会这样做,所以我做了一个讨厌的解决方法,使用秒表,测量*** IMMEDIATELY CLOSED -> AnotherNETLib.dll!AnotherNETLib.AnotherNETLibClass.XXXXDialog.XXXXDialog_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e) Line 119 C#
System.Windows.Forms.dll!System.Windows.Forms.Form.OnFormClosing(System.Windows.Forms.FormClosingEventArgs e) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Form.CheckCloseDialog(bool closingOnly) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FContinueMessageLoop(int reason, int pvLoopData, System.Windows.Forms.NativeMethods.MSG[] msgPeeked) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.RunDialog(System.Windows.Forms.Form form) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window owner) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog() Unknown
*** CALLS "dlg.ShowDialog();" -> AnotherNETLib.dll!AnotherNETLib.AnotherNETLibClass.ShowXXXXDialog() Line 719 C#
[Native to Managed Transition]
[Managed to Native Transition]
[Native to Managed Transition]
*** CALLS TO A .NET LIB VIA COM -> NativeCOMLib.dll!ATL::CComPtr<IDispatch>::Invoke0(long dispid, tagVARIANT * pvarRet) Line 465 C++
NativeCOMLib.dll!ATL::CComPtr<IDispatch>::Invoke0(const wchar_t * lpszName, tagVARIANT * pvarRet) Line 475 C++
NativeCOMLib.dll!CNativeClass::ShowXXXXDialog() Line 204 C++
NativeCOMLib.dll!CNativeClass::FinalConstruct() Line 130 C++
NativeCOMLib.dll!ATL::CComCreator<ATL::CComObject<CNativeClass> >::CreateInstance(void * pv, const _GUID & riid, void * * ppv) Line 2009 C++
NativeCOMLib.dll!ATL::CComCreator2<ATL::CComCreator<ATL::CComObject<CNativeClass> >,ATL::CComCreator<ATL::CComAggObject<CNativeClass> > >::CreateInstance(void * pv, const _GUID & riid, void * * ppv) Line 2094 C++
NativeCOMLib.dll!ATL::CComClassFactory::CreateInstance(IUnknown * pUnkOuter, const _GUID & riid, void * * ppvObj) Line 3738 C++
[Managed to Native Transition]
mscorlib.dll!System.RuntimeType.CreateInstanceSlow(bool publicOnly, bool skipCheckThis, bool fillCache, ref System.Threading.StackCrawlMark stackMark) Line 5430 C#
mscorlib.dll!System.Activator.CreateInstance(System.Type type, bool nonPublic) Line 193 C#
mscorlib.dll!System.Activator.CreateInstance(System.Type type) Line 134 C#
*** CALLS TO NATIVE COM -> Main_AppNET.exe!MainApp.Libs.LoadLib(string id) Line 71 C#
Main_AppNET.exe!MainApp.MainForm.MainForm_Load(object sender, System.EventArgs e) Line 654 C#
System.Windows.Forms.dll!System.Windows.Forms.Form.OnLoad(System.EventArgs e) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Form.OnCreateControl() Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl() Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.WmShowWindow(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Form.WmShowWindow(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m) Unknown
Main_AppNET.exe!MainApp.MainForm.WndProc(ref System.Windows.Forms.Message m) Line 637 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m) Unknown
Infragistics2.Win.UltraWinTabbedMdi.v9.2.dll!Infragistics.Win.UltraWinTabbedMdi.MdiParentSubclasser.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
[Native to Managed Transition]
user32.dll!_InternalCallWinProc@20() Unknown
user32.dll!_UserCallWinProcCheckWow@32() Unknown
user32.dll!_SendMessageWorker@24() Unknown
user32.dll!_SendMessageW@16() Unknown
System.Windows.Forms.ni.dll!7a6190d0() Unknown
[Frames below may be incorrect and/or missing, native debugger attempting to walk managed call stack]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Form.SetVisibleCore(bool value) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.Visible.set(bool value) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) Unknown
***APP STARTUP -> Main_AppNET.exe!MainApp.Program.Main(string[] args) Line 127 C#
[Native to Managed Transition]
mscoreei.dll!__CorExeMain@0() Unknown
mscoree.dll!_ShellShim__CorExeMain@0() Unknown
mscoree.dll!__CorExeMain_Exported@0() Unknown
ntdll.dll!___RtlUserThreadStart@8() Unknown
ntdll.dll!__RtlUserThreadStart@8() Unknown
的时间,如果返回<1秒,我期待上述问题,以及再打一次。它有效...但我很好奇发生了什么事?