Textbox doesn't get updated while threading

后端 未结 3 672
囚心锁ツ
囚心锁ツ 2021-01-24 07:52

Here is a sub code inside a module named \"Blahing\":

    Sub BlahBlah(ByVal Count As Long)
        For i As Long = 0 To Count
            frmBlaher.txtBlah.Appe         


        
3条回答
  •  温柔的废话
    2021-01-24 08:12

    Run your code a little bit different, This is how the Structure should look like for Multithreading in vb.net ( it has something to do with Vb.net not passing Namespaces into Models from what i Understand )

    This would be your startThread from MainThread in load or w/e have you

    Private Sub DoSomethingSimple()
        Dim DoSomethingSimple_Thread As New Thread(AddressOf DoSimple)
        DoSomethingSimple_Thread.Priority = ThreadPriority.AboveNormal
        DoSomethingSimple_Thread.Start(Me)
    End Sub
    

    This would be the actual thread Itself ( new model / class or in the same class )

    Private Sub DoSimple(beginform As Form)
        'Do whatever you are doing that has nothing to do with ui
    
        'For UI calls use the following
        SomethingInvoked(PassibleVariable, beginform)
    
    End Sub
    

    Write a Delegate and Invoke Method for Each Call to the Main Thread.

    Delegate Sub SomethingInvoked_Delegate(s As Integer, beginform As Form)
    Sub SomethingInvoked_Invoke(ByVal s As Integer, beginform As Form)
        If beginform.NameOfControlYouAreUpdating.InvokeRequired Then ' change NameOfControlYouAreUpdating to the Name of Control on the form you wish to update
            Dim d As New SomethingInvoked_Delegate(AddressOf SomethingInvoked_Invoke)
            beginform.Invoke(d, New Object() {s, beginform})
        Else
    
            'Do something...
            beginform.NameOfControlYouAreUpdating.Condition = Parameter
    
        End If
    End Sub
    

    This is tested ( non hanging ) way of writing Threads in vb.net

    If you need further help implementing your code to this Template let me know :P

提交回复
热议问题