Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7595541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:41:47+00:00 2026-05-30T21:41:47+00:00

Updating the TextBox from a Thread that calls a function within a Class does

  • 0

Updating the TextBox from a Thread that calls a function within a Class does not work. I’m trying to get this to work in a DLL (but I tried without as well). The DLL is accepting an Object as an argument, like so;

Sub New(ByVal theObject As Object)

This allows me to send an object such as this one:

Public Class anObject
    Public Sub doSomething()
        Form1.TextBox1.Text = "test"
    End Sub
End Class

So I will be calling the DLL like this:

Dim theObject As New anObject
Dim theDLL As New SO_TBFromDLL.UpdateTB(theObject)

After which the DLL will start a Thread, that then calls “doSomething”

Public Class UpdateTB
    Dim theObjectSet As Object

    Sub New(ByVal theObject As Object)
        theObjectSet = theObject

        'Try to update TB from Thread within current class
        Dim ctThread As Threading.Thread = New Threading.Thread(AddressOf bghandler)
        ctThread.Start()
    End Sub

    'Try to update TB from Thread within current class
    Sub bghandler()
        theObjectSet.doSomething()
    End Sub
End Class

But this isn’t working. I also tried it using a delegate (code below).

I have been trying two other variations in addition to those two;

Try 3 from Thread that’s not in Class/DLL. This works just fine.

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Dim ctThread As Threading.Thread = New Threading.Thread(AddressOf receiverFunction)
    ctThread.Start()
End Sub

With receiverFunction being:

'Receiver for Thread that's not in DLL (Button 3)
Private Sub receiverFunction()
    generaldelegatesN("tb1", "test")
End Sub

Try 4 from Thread that’s not in DLL, but use the Function inside of the Class. This does not work either.

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    Dim theObject As New anObjectWithDelegate
    Dim ctThread As Threading.Thread = New Threading.Thread(AddressOf theObject.doSomething)
    ctThread.Start()
End Sub

With anObjectWithDelegate being:

'Unfortunately, with a delegate it still doesn't work (Button2 & Button4)
Public Class anObjectWithDelegate
    Public Sub doSomething()
        Form1.generaldelegatesN("tb1", "test")
    End Sub
End Class

Why does Try 3 work, but Try 4 doesn’t? It’s doSomething() function is practically identical to receiverFunction With the exception of the added Form1.

Delegation code: (In case it matters)

'The Delegate functions
Delegate Sub generaldelegates(ByVal param1 As String, ByVal param2 As String)
Public generaldelegatesM As generaldelegates
Public Sub generaldelegatesN(ByVal param1 As String, ByVal param2 As String)
    'Updates control on main thread:
    If Me.InvokeRequired Then
        generaldelegatesM = New generaldelegates(AddressOf generaldelegatesN)
        Me.BeginInvoke(generaldelegatesM, New Object() {param1, param2})
    Else
        Select Case param1
            Case "tb1"
                TextBox1.Text = param2
        End Select
    End If
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:41:48+00:00Added an answer on May 30, 2026 at 9:41 pm

    You’re trying to hard code a reference to an external object inside a separate class that has no idea about what objects are instantiated elsewhere. Your class object would need to have the textbox reference passed to it like this :

    Public Class Form1
    
        Private myObject = New anObject
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            myObject.doSomething(TextBox1, "test")
        End Sub
    
    End Class
    
    Public Class anObject
        Public Sub doSomething(ByRef obj As Object, ByVal message as String)
            Dim objType = obj.GetType()
    
            If objType Is GetType(TextBox) Then obj.Text = message
    
        End Sub
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For whatever reason - my update panel is not updating. Now please note that
I'm trying to analyze audio using AudioRecord in a class. My problem is that
there. I'm using C# .wpf, and I get this some code from C# source,
I'm playing with a custom TextBox inheriting from the WPF TextBox, trying to learn
Does updating statistics cause tables to be inaccessible? In other words, can you run
When updating a DataTable with 1850-ish new rows to a FbDataAdapter I get a
After updating to Parsec 3.1 from 2.x, code using many1, such as word =
I have an updatepanel that includes a textbox, a buttun (named 'search') and a
I'm learning Databinding from here http://www.akadia.com/services/dotnet_databinding.html I'm just updating the dataset and then updating
I am creating a calculator view that uses sliders to set textbox values. Each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.