Results 1 to 6 of 6

Thread: Should I use "Invoke" for this goal?

  1. #1

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Should I use "Invoke" for this goal?

    Hi. Due to running a bunch of try catches, wmi and Performance counters, A form load event will take a lot of time to be done. (Like a massive loop) I'm already using BackgroundWorker for other purposes but I assume that Form load event is better to take a tangible visual.

    I only want to set Me.Cursor = Cursors.Wait or Me.UseWaitCursor = True . (By the way, What are the differences between these two? What should I use)

    Then reset it to default only for user to understand the app is still responding and PC is not "hang". Unfortunately 2 mentioned ways were tried and no waiting cursors occurred. I read somewhere BeginInvoke (And EndInvoke) can make this happen, but how?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Should I use "Invoke" for this goal?

    You shouldn’t use Form_Load for that type of large loop. Use the Form’s Constructor so the code is run before the form is loaded

  3. #3

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Re: Should I use "Invoke" for this goal?

    Thanks .paul. so the order would be constructor, load, shown right? What about user controls? They do not have such event. Plus, my problem seems a synchronous %CPU high load thing how can I overcome it? For instance showing a messagebox in this stage opens it semi-transparency. Box is not completely displayed (Corresponding audio also won't play) until that heavy load passes, everything back to normal.

  4. #4

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Re: Should I use "Invoke" for this goal?

    I immediately regretted my decision. By constructor you mean
    Code:
    Public Class MYUSERCONTROL
         Public Sub New()
              Me.InitializeComponent()
         End Sub
    
         Private Sub InitializeComponent()
    
         End Sub
    End Class
    ?

    If so, what is the correct way to write it down? Cause I already have errors:
    1) BC30269 'Private Sub InitializeComponent()' has multiple definitions with identical signatures.
    2) BC30521 Overload resolution failed because no accessible 'InitializeComponent' is most specific for these arguments:
    'Private Sub InitializeComponent()': Not most specific.
    'Private Sub InitializeComponent()': Not most specific.
    Last edited by pourkascheff; Jul 20th, 2023 at 12:33 AM.

  5. #5

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    384

    Re: Should I use "Invoke" for this goal?

    May I also draw your attention to this part, partially?
    Quote Originally Posted by pourkascheff View Post
    Me.Cursor = Cursors.Wait or Me.UseWaitCursor = True . (By the way, What are the differences between these two? What should I use)

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Should I use "Invoke" for this goal?

    Quote Originally Posted by pourkascheff View Post
    I immediately regretted my decision. By constructor you mean
    Code:
    Public Class MYUSERCONTROL
         Public Sub New()
              Me.InitializeComponent()
         End Sub
    
         Private Sub InitializeComponent()
    
         End Sub
    End Class
    ?

    If so, what is the correct way to write it down? Cause I already have errors:
    1) BC30269 'Private Sub InitializeComponent()' has multiple definitions with identical signatures.
    2) BC30521 Overload resolution failed because no accessible 'InitializeComponent' is most specific for these arguments:
    'Private Sub InitializeComponent()': Not most specific.
    'Private Sub InitializeComponent()': Not most specific.
    There should already be a sub InitializeComponents() in the .designer file of the form... no need for you to create one. Any initialization code you want to add should go after the Me.InitialzeComponent() call in the constructor.


    Code:
    Public Class MYUSERCONTROL
         Public Sub New()
              Me.InitializeComponent()
              ' Add additional code here
         End Sub
    
         ' Private Sub InitializeComponent()
         ' Removed this
         ' End Sub
    End Class

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Tags for this Thread

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