Results 1 to 6 of 6

Thread: Execute code after Form Load [Resolved]

  1. #1

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Execute code after Form Load [Resolved]

    I need to execute this code during form load but the problem is that it either takes ages to show the form or does things I don't want it to do. Is there a way to run code in parallel with the form load so that the form still shows, but the extra code that is required to execute at the start, still operates?

    An example would be if you try to hide the form in the Form_Load procedure, as soon as the procedure has finished, the form shows itself in the taskbar, even if you have chosen to hide it.
    Last edited by Ideas Man; Aug 21st, 2004 at 07:50 PM.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

  2. #2
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    I would simply run the code in a new thread
    Whadayamean it doesn't work....
    It works fine on my machine!

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    If you use sub Main in the module as your startup object, you could try:

    VB Code:
    1. Module Module1
    2.  
    3.     Public frm1 As Form
    4.    
    5.     Sub Main()
    6.         FirstAction
    7.         frm1 = New Form1
    8.         frm1.ShowDialog()
    9.     End Sub
    10.  
    11.     Private SubFirstAction()
    12.         MessageBox.Show("This is your FirstAction code")
    13.     End Sub
    14.  
    15. End Module
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Another approach is to have a splash screen, maybe with a bogus progress bar (like when you start Windows) or animation. Then you can do lots of stuff before you show your main form, and the user doesn't think your app is hanging or slow.

    Mike

  5. #5

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718
    Originally posted by CyberHawke
    I would simply run the code in a new thread
    How would i do that?

    And thanks for those other suggestions, but they really only do what it does now, but in a different way. Taxes suggestion would be stuck in the subroutine before loading the form so it's just moving the problem to a different location.

    I need it like a timer so that it executes in parallel, CyberHawke sounds like he is on the track.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

  6. #6

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718
    Thankyou CyberHawke, you solved my problem.

    For all those looking for a solution, I found the Multi-threadding solution at here: http://msdn.microsoft.com/library/de...eThreading.asp
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width