Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

vb.net - Form.Load event not firing, form showing

I fear that there is something obviously wrong with my code, but I have come across a situation where the Form.Load event is not firing when I create and show my form.

The form is not subclassed (as I've seen some problems with that in some searches), and I am not getting any errors thrown when I step through the code in the debugger.

I have a break point set on the IDE-created form load function (which does have the Handles MyBase.Load signature suffix) but the breakpoint is never reached and the form does display and work.

The form is passed three arguments in the constructor but the IntializeComponent() function is called before anything else is done.

Code:

Public Sub New(ByVal argA As Object, ByVal argB As Object, ByVal mode As FormMode)

    ' This call is required by the Windows Form Designer.
    InitializeComponent()

    ' Other code here,
    ' No errors generated
    '

End Sub

The form load function is as follows, (but this is never actually executed as the event is not fired).

Code:

Private Sub frmInstrumentEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If Not argA Is Nothing Then ' argA set in constructor
          ' Operations using argA
    End If
End Sub

I might add I am using some databinding with some controls and the argA object, but if this was producing an error I thought I would have seen this (I have CLR Execpetions settings set to Thown in the debugger > exceptions window)

Any ideas why this might be occurring?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I just had a similar issue (it was in Shown event, not Load, but the root cause is the same). The reason was hidden deep in one of the ancestors - there was an unhandled NullReferenceException thrown and this exception was somehow "muted".

I found it after extensive debugging with F11.

But... when writing this answer I found this post on SO

Just add Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException) in your Main() method.

If you're using a 64-bit machine, it provides you with the solution (it worked in my case, too).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...