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

  • SEARCH
  • Home
  • 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 1061243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:26:52+00:00 2026-05-16T18:26:52+00:00

I have a thread running on a child form, I want to activate a

  • 0

I have a thread running on a child form, I want to activate a control on the parent form but cannot. It works fine if It’s done from the child forms UI thread:

(FormMain.SetControlPropertyValue(FormMain.RBSQL2005, “Checked”, True))

but not from a thread running on the child form:

Public Class FormRestoreDB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim t = New Thread(AddressOf UpdateListView1)
    t.Start()
End Sub


Private Sub UpdateListView1()
    'FormMain.SetControlPropertyValue(FormMain.RBSQL2005, "Checked", True)
    FormMain.RBSQL2005.Checked = True
End Sub

End Class


Public Class FormMain

Delegate Sub SetControlValueCallback(ByVal oControl As Control, ByVal propName As String, ByVal propValue As Object)

Public Sub SetControlPropertyValue(ByVal oControl As Control, ByVal propName As String, ByVal propValue As Object)
    If (oControl.InvokeRequired) Then

        Dim d As New SetControlValueCallback(AddressOf SetControlPropertyValue)
        oControl.Invoke(d, New Object() {oControl, propName, propValue})
    Else
        Dim t As Type = oControl.[GetType]()
        Dim props As PropertyInfo() = t.GetProperties()
        For Each p As PropertyInfo In props
            If p.Name.ToUpper() = propName.ToUpper() Then
                p.SetValue(oControl, propValue, Nothing)
            End If
        Next
    End If
End Sub

End Class

What am I doing wrong?

alt text

  • 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-16T18:26:52+00:00Added an answer on May 16, 2026 at 6:26 pm
     FormMain.SetControlPropertyValue(FormMain.RBSQL2005, "Checked", True)
    

    This is one of the horrors induced by VB.NET’s support for using the type name of a form to refer to the instance of the form. It is an anachronism carried over from VB6 where using the type name of a form was normal.

    This falls apart when you use threads because “FormMain” has thread affinity. In other words, it has the <ThreadStatic> attribute. When you use it in a worker thread then you get a new instance of the form, not the one that the user is looking at. This new instance isn’t visible because its Show() method was never called. Which is why you don’t see your code having any effect. If you call Show() in your code then you’ll see it pop up. It is however quite dead, the thread isn’t pumping a message loop. Another effect you should have noticed was that InvokeRequired is False, you know that can’t be right.

    You will have to stop using FormMain. If this code lives inside that class then you can simply use Me. If it doesn’t then you’ll have to pass the form reference with a property or a constructor argument. The Q&D fix is to use Application.OpenForms(0)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my main GUI thread, and a second thread running inside it's own
In my C# program, I have a thread that represents a running test, which
I have a method running in a seperate thread. The thread is created and
I have a long running series of operations in a .NET 2.0 BackgroundWorker thread.
I have a timely operation that runs on a background thread. While running, I
I need some help with C++. I have a thread running in the background
I have a thread downloading data and I want to wait until the download
I have multiple threads (C# application running on IIS) running that all need to
I have a program 'foo' running different threads, fooT1, fooT2, .. fooTn. Now if
I have thread exception handler which saves the exception stack trace and should close

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.