I have a VB6 app, which does a lot of processing in the form_load. A call to DoEvents ensures that the form loads before the processing is complete. However,this does not appear to work in VB.NET i.e. in the following code, the loop finishes befoRe the form is loaded, even though I have called DOEVENTS:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
For i = 0 To 100000
Application.DoEvents()
Dim Test As String = "Test"
Next
End Sub
What have I missed?
Your statement:
To the best of my knowledge, this is NOT true. The form “paints” before processing your load event – the processing (that is loading) is still not complete. All that is ensured by a call to DoEvents is OTHER messages get a chance to be handled when you are in the middle of a long processing. MSDN’s help of DoEvent() describes it as:
Also, it specifically states:
I believe it might be risky for you to handle your requirement in the Load event. Just a search for “Application.DoEvents in load” in google talks about bad experiences for many. I suggest you can explore handling your requirement in Shown event.