none
Calling invoke from a module RRS feed

  • Question

  • Dear all,
    i've this problem, i've a client server application.
    Sometimes the server send a raise event to the client application through net socket, the client application have to generate a control on the main form executing code in a module.
    The trouble is that i've no mode to found any control to call an invoke method to execute the code on the main thread in this module...so the control doesn't appear.

    Many thank.
    Genko.

    Monday, March 19, 2018 8:04 PM

Answers

  • Dear all,
    i've this problem, i've a client server application.
    Sometimes the server send a raise event to the client application through net socket, the client application have to generate a control on the main form executing code in a module.
    The trouble is that i've no mode to found any control to call an invoke method to execute the code on the main thread in this module...so the control doesn't appear.

    Many thank.
    Genko.

    You'll need a reference to the main form in the module.  Here is a test module

    Module Module1
    
        Public MainForm As Form1
    
        Public Sub test()
            MainForm.BeginInvoke(Sub()
                                     MainForm.TextBox1.Text = "HELLO"
                                 End Sub)
        End Sub
    
        '
        'etc.
        '
    
    End Module
    

    Here is the shown event of the main form

        Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            Module1.MainForm = Me
            Module1.test() 'as a test
        End Sub
    

    Hope this helps.


    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it" - MSDN User JohnWein

    • Marked as answer by _Genko_ Monday, March 19, 2018 9:02 PM
    Monday, March 19, 2018 8:48 PM

All replies

  • Dear all,
    i've this problem, i've a client server application.
    Sometimes the server send a raise event to the client application through net socket, the client application have to generate a control on the main form executing code in a module.
    The trouble is that i've no mode to found any control to call an invoke method to execute the code on the main thread in this module...so the control doesn't appear.

    Many thank.
    Genko.

    You'll need a reference to the main form in the module.  Here is a test module

    Module Module1
    
        Public MainForm As Form1
    
        Public Sub test()
            MainForm.BeginInvoke(Sub()
                                     MainForm.TextBox1.Text = "HELLO"
                                 End Sub)
        End Sub
    
        '
        'etc.
        '
    
    End Module
    

    Here is the shown event of the main form

        Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            Module1.MainForm = Me
            Module1.test() 'as a test
        End Sub
    

    Hope this helps.


    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it" - MSDN User JohnWein

    • Marked as answer by _Genko_ Monday, March 19, 2018 9:02 PM
    Monday, March 19, 2018 8:48 PM
  • many thanks JohnWein!


    Monday, March 19, 2018 9:02 PM
  • many thanks JohnWein!


     That is dbasnett that answered your question.  He just has a quote from a past member named John Wein at the bottom of his posts.   8)


    If you say it can`t be done then i`ll try it

    Monday, March 19, 2018 9:16 PM