[VB] Event not firing

Discussion in 'Mixed Languages' started by QuantumBug, Feb 21, 2016.

  1. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,488
    1,324
    60
    #1 QuantumBug, Feb 21, 2016
    Last edited by a moderator: Apr 20, 2017
    I wrote this code to mimic a "Shown" event within a UserControl as I need to start threads after the UI has been created.

    Code:
    Private WithEvents pf As Form
    Code:
    Protected Overrides Sub OnParentChanged(e As EventArgs)
    pf = Me.ParentForm
    MyBase.OnParentChanged(e)
    End Sub
    Code:
    Private pf_shown(sender As Object, e As EventArgs) Handles pf.Shown
    '//Run threads
    End Sub
    I was so sure the code would work but it doesn't fire the threads even after the UI has been created. Could anyone explain why? Or maybe I'm just going about it incorrectly.

    I have also checked child forms know what their parent is and that seems to be fine.

    Regards, The Dev.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Michaela Joy

    Michaela Joy MDL Crazy Lady

    Jul 26, 2012
    3,502
    3,685
    120
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,488
    1,324
    60
    Lol, I think Visual Studio must have had a bitch moment.

    It's working now and the InvalidOperatingExceptions and ThreadAbortExceptions are gone.

    Thanks MJ.


    Don't worry, I left the threads in the form load event.

    Sighs hard.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Michaela Joy

    Michaela Joy MDL Crazy Lady

    Jul 26, 2012
    3,502
    3,685
    120
    Please remember that I'm not a VB programmer, so take my reply with a grain of salt. :)

    In my form code, (Yes...Delphi has forms too. :D ) I would put a message handler and in my startup code and I would post a windows message (WM_USER + XXXX) to indicate that it was safe to create / execute my thread. (The message handler would start the thread.)

    The other way (A little more complicated from a VB standpoint) would be to create a timer and start it when my initialization was complete. The OnTimer handler would execute the startup of the thread.

    Just some thoughts FWIW...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...