在“Dim mdi as new MDIParent1”中遇到异常在VB.NET中
我在这段代码中遇到异常:
Imports System.Windows.Forms
Imports System.Text
Imports System.Diagnostics
Public Class MDIParent1
Private Sub MDIParent1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
getapp.getApplication()
End Sub
Public Sub MDIParent1(ByVal value As String, ByVal value1 As String)
Dim ChildForm As New System.Windows.Forms.Form
ChildForm.MdiParent = Me
ChildForm.Text = value1
ChildForm.Show()
End Sub
End Class
Public Class getApplications
Dim w As String
Dim b As New Process()
Dim p As String
Dim mdi As New MDIParent1 'here i am getting exception that is System.StackOverflowException was unhandled InnerException:..
Dim i As Integer
Public Sub getApplication()
For Each Me.b In Process.GetProcesses(".")
Try
If b.MainWindowTitle.Length > 0 Then
p = b.ProcessName.ToString()
w = b.MainWindowTitle().ToString()
mdi.MDIParent1(p, w)
End If
Catch
End Try
Next
End Sub
End Class
I'm getting an exception in this code:
Imports System.Windows.Forms
Imports System.Text
Imports System.Diagnostics
Public Class MDIParent1
Private Sub MDIParent1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
getapp.getApplication()
End Sub
Public Sub MDIParent1(ByVal value As String, ByVal value1 As String)
Dim ChildForm As New System.Windows.Forms.Form
ChildForm.MdiParent = Me
ChildForm.Text = value1
ChildForm.Show()
End Sub
End Class
Public Class getApplications
Dim w As String
Dim b As New Process()
Dim p As String
Dim mdi As New MDIParent1 'here i am getting exception that is System.StackOverflowException was unhandled InnerException:..
Dim i As Integer
Public Sub getApplication()
For Each Me.b In Process.GetProcesses(".")
Try
If b.MainWindowTitle.Length > 0 Then
p = b.ProcessName.ToString()
w = b.MainWindowTitle().ToString()
mdi.MDIParent1(p, w)
End If
Catch
End Try
Next
End Sub
End Class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是你有一个永远不会结束的递归调用。
MDIParent1.MDIParent1() 调用 getApplications.getApplication(),
哪个调用
MDIParent1.MDIParent1(),再次调用 getApplications.getApplication(),
哪个调用
MDIParent1.MDIParent1(),再次调用 getApplications.getApplication(),
哪个调用
MDIParent1.MDIParent1(),再次调用 getApplications.getApplication(),
哪个调用
MDIParent1.MDIParent1(),再次调用 getApplications.getApplication(),
哪个调用
MDIParent1.MDIParent1(),再次调用 getApplications.getApplication(),
哪个调用
MDIParent1.MDIParent1(),它再次调用 getApplications.getApplication(),
依此类推直至无穷大(或直到系统抛出 StackOverflowException)。
The problem is that you have a recursive call that never ends.
MDIParent1.MDIParent1() calls getApplications.getApplication(),
which calls
MDIParent1.MDIParent1(), which again calls getApplications.getApplication(),
which calls
MDIParent1.MDIParent1(), which again calls getApplications.getApplication(),
which calls
MDIParent1.MDIParent1(), which again calls getApplications.getApplication(),
which calls
MDIParent1.MDIParent1(), which again calls getApplications.getApplication(),
which calls
MDIParent1.MDIParent1(), which again calls getApplications.getApplication(),
which calls
MDIParent1.MDIParent1(), which again calls getApplications.getApplication(),
and so on into infinity (or until the system throws a StackOverflowException).
当您创建
MDIParent1
实例时,您将调用getApplication()
。当您调用getApplication()
时,您将创建一个MDIParent1
的新实例。这是无限递归导致堆栈溢出异常。您实际上尝试使用这段代码做什么?
When you create an instance of
MDIParent1
you callgetApplication()
. When you callgetApplication()
you create a new instance ofMDIParent1
. It's an infinite recursion resulting in a stack overflow exception.What are you actually trying to do with this code?
如果将 New 与 Dim 分开分配,您会得到相同的异常吗?
Do you get the same Exception if you assign New separately from Dim?