(1)開發環境 Development Environment
WinXP (32-bit x86) SP3
VS.NET 2008
.Net Framework 3.5
VB WinForm
MDI Form
(2)程式碼 Code
'建立新的子表單
Private Sub ShowMDIForm(ByVal p_mdi As Form)
p_mdi.MdiParent = Me
'p_mdi.Owner = Me
p_mdi.WindowState = FormWindowState.Maximized
p_mdi.Show()
End Sub
'檢查是否子表單已存在
Function checkFormExist(ByVal FormText As String) As Boolean
Dim bFound As Boolean = False
For Each f As Form In Me.MdiChildren
If f.Text.Equals(FormText) Then
f.Activate()
bFound = True
Exit For
End If
Next
Return bFound
End Function
'建立子表單
Private Sub TreeView1_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
Dim l_Frm As Form = New Form
Select Case e.Node.Text
Case "個資管理"
l_Frm = New MGMT_Personal
Case "薪資管理"
l_Frm = New MGMT_Salary
Case "任職管理"
l_Frm = New MGMT_P
Case "事項管理"
l_Frm = New MGMT_ImptItem
End Select
'判斷存表單是否已存在 - 若否則開啟 New & Show
If checkFormExist(l_Frm.Text) = False Then
ShowMDIForm(l_Frm)
End If
'判斷存表單是否已存在 - 若是則開啟 Activate
If l_Frm IsNot Nothing Then
For i As Integer = 0 To Me.MdiChildren.Length - 1
If e.Node.Text.Equals(Me.MdiChildren(i).Text) Then
Me.MdiChildren(i).Activate()
'Return
End If
Next
End If
End Sub
(3)參考畫面
(4)錯誤產生時間
當點選 "任職管理" 再點選其它 "表單選項" 便會發生 Error!
(5)參考辦法
疑難排解例外狀況:System.OutOfMemoryException
使用過多的 Managed 記憶體,通常是因為:
- 將大量資料集讀入記憶體中。
- 建立過多的快取項目。
- 上傳或下載大型檔案。
- 剖析檔案時,使用太多規則運算式 (Regular Expression) 或字串。
- 檢視狀態過多。
- 工作階段狀態中有過多資料,或工作階段過多。
在 COM 物件上叫用方法,而且這個 COM 物件會傳回包含安全陣列 (非固定大小的陣列) 的使用者定義型別時,便可能會擲回這個例外狀況,其中的訊息為:「存放裝置空間不足,無法完成此操作」。這是因為 .NET Framework 無法封送處理具有安全陣列型別的結構欄位。
(6)錯誤訊息
System.OutOfMemoryException 未處理Message="建立視窗控制代碼時發生錯誤。"
Source="System.Windows.Forms"
StackTrace:
於 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp) 於 System.Windows.Forms.Control.CreateHandle() 於 System.Windows.Forms.Form.CreateHandle() 於 System.Windows.Forms.Control.get_Handle() 於 System.Windows.Forms.Form.SetVisibleCore(Boolean value) 於 System.Windows.Forms.Control.Show() 於 eHRsys.MAIN_ligoHRsys.ShowMDIForm(Form p_mdi) 於 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\eHRsys\eHRsys\MAIN_ligoHRsys.vb: 行 33 於 eHRsys.MAIN_ligoHRsys.TreeView1_NodeMouseClick(Object sender, TreeNodeMouseClickEventArgs e) 於 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\eHRsys\eHRsys\MAIN_ligoHRsys.vb: 行 74 於 System.Windows.Forms.TreeView.OnNodeMouseClick(TreeNodeMouseClickEventArgs e) 於 System.Windows.Forms.TreeView.WmNotify(Message& m) 於 System.Windows.Forms.TreeView.WndProc(Message& m) 於 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 於 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 於 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 於 System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) 於 System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam) 於 System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m) 於 System.Windows.Forms.Control.WmNotify(Message& m) 於 System.Windows.Forms.Control.WndProc(Message& m) 於 System.Windows.Forms.ScrollableControl.WndProc(Message& m) 於 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 於 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 於 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 於 System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) 於 System.Windows.Forms.NativeWindow.DefWndProc(Message& m) 於 System.Windows.Forms.Control.DefWndProc(Message& m) 於 System.Windows.Forms.TreeView.WmMouseDown(Message& m, MouseButtons button, Int32 clicks) 於 System.Windows.Forms.TreeView.WndProc(Message& m) 於 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 於 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 於 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 於 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 於 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) 於 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 於 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) 於 System.Windows.Forms.Application.Run(ApplicationContext context) 於 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() 於 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() 於 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) 於 eHRsys.My.MyApplication.Main(String[] Args) 於 17d14f5c-a337-4978-8281-53493378c1071.vb: 行 81 於 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) 於 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 於 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 於 System.Threading.ThreadHelper.ThreadStart_Context(Object state) 於 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 於 System.Threading.ThreadHelper.ThreadStart()
InnerException: System.NullReferenceException
Message="並未將物件參考設定為物件的執行個體"
Source="System.Windows.Forms"
StackTrace:
於 System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 於 System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam) 於 System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam) 於 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
InnerException:
-------------------------------------------------------------------------
如需叫用 Just-In-Time (JIT) 偵錯的詳細資料,
請參閱本訊息結尾處 (而非這個對話方塊) 的資訊。
************** 例外狀況文字 **************
System.OutOfMemoryException: 建立視窗控制代碼時發生錯誤。 ---> System.NullReferenceException: 並未將物件參考設定為物件的執行個體
於 System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
於 System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
於 System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
於 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
--- 內部例外狀況堆疊追蹤的結尾 ---
於 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
於 System.Windows.Forms.Control.CreateHandle()
於 System.Windows.Forms.Form.CreateHandle()
於 System.Windows.Forms.Control.get_Handle()
於 System.Windows.Forms.Form.SetVisibleCore(Boolean value)
於 System.Windows.Forms.Control.Show()
於 eHRsys.MAIN_ligoHRsys.ShowMDIForm(Form p_mdi) 於 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\eHRsys\eHRsys\MAIN_ligoHRsys.vb: 行 9
於 eHRsys.MAIN_ligoHRsys.TreeView1_NodeMouseClick(Object sender, TreeNodeMouseClickEventArgs e) 於 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\eHRsys\eHRsys\MAIN_ligoHRsys.vb: 行 55
於 System.Windows.Forms.TreeView.OnNodeMouseClick(TreeNodeMouseClickEventArgs e)
於 System.Windows.Forms.TreeView.WmNotify(Message& m)
於 System.Windows.Forms.TreeView.WndProc(Message& m)
於 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
於 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
於 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** 已載入的組件 **************
mscorlib
組件版本: 2.0.0.0
Win32 版本: 2.0.50727.3634 (GDR.050727-3600)
程式碼基底: file:///C:/WINNT/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
eHRsys
組件版本: 1.0.0.0
Win32 版本: 1.0.0.0
程式碼基底: file:///C:/Documents%20and%20Settings/Administrator/My%20Documents/Visual%20Studio%202008/Projects/eHRsys/eHRsys/bin/Debug/eHRsys.exe
----------------------------------------
Microsoft.VisualBasic
組件版本: 8.0.0.0
Win32 版本: 8.0.50727.3053 (netfxsp.050727-3000)
程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
組件版本: 2.0.0.0
Win32 版本: 2.0.50727.3634 (GDR.050727-3600)
程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
組件版本: 2.0.0.0
Win32 版本: 2.0.50727.3637 (GDR.050727-3600)
程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
組件版本: 2.0.0.0
Win32 版本: 2.0.50727.3639 (GDR.050727-3600)
程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
組件版本: 2.0.0.0
Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
組件版本: 2.0.0.0
Win32 版本: 2.0.50727.3082 (QFE.050727-3000)
程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
組件版本: 2.0.0.0
Win32 版本: 2.0.50727.3053 (netfxsp.050727-3000)
程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.Windows.Forms.resources
組件版本: 2.0.0.0
Win32 版本: 2.0.50727.1433 (REDBITS.050727-1400)
程式碼基底: file:///C:/WINNT/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_zh-CHT_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------
mscorlib.resources
組件版本: 2.0.0.0
Win32 版本: 2.0.50727.3634 (GDR.050727-3600)
程式碼基底: file:///C:/WINNT/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
************** JIT 偵錯 **************
若要啟用 Just-In-Time (JIT) 偵錯功能,則必須在
此應用程式或電腦的 .config 檔案中,設定
system.windows.forms 區段內的 jitDebugging 值。
且該應用程式也必須在啟用偵錯的狀態下進行
編譯。
例如:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
當 JIT 偵錯功能啟用後,會將所有未處理的例外
狀況傳送給電腦上已註冊的 JIT 偵錯工具進行處
理,而不是使用這個對話方塊來處理。
沒有留言:
張貼留言