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 3223784
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:08:50+00:00 2026-05-17T16:08:50+00:00

I’ve been reading around trying to find out why I’d be getting this exception

  • 0

I’ve been reading around trying to find out why I’d be getting this exception to no avail. I hope someone has seen this before:

I’m using Visual Basic 2010.

Briefly, I have a “Settings Panel” form which takes a while to create (it contains a lot of labels and textboxes), so I create it in another thread.

After it’s loaded, it can be viewed by clicking a button which changes the form’s visibility to True. I use the following subroutine to handle invokes for my controls:

Public Sub InvokeControl(Of T As Control)(ByVal Control As T, ByVal Action As Action(Of T))
        If Control.InvokeRequired Then
            Control.Invoke(New Action(Of T, Action(Of T))(AddressOf InvokeControl), New Object() {Control, Action})
        Else
            Action(Control)
        End If
End Sub

Here’s the relevant part of my main code (SettingsTable inherits TableLayoutPanel and HelperForm inherits Form):

Public Class ch4cp
Public RecipeTable As SettingsTable
Public WithEvents SettingsWindow As HelperForm

Private Sub ch4cp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

PanelCreatorThread = New Threading.Thread(AddressOf CreateStartupPanels)
        PanelCreatorThread.Start()

End Sub

 Private Sub CreateStartupPanels()

        SettingsWindow = New HelperForm("Settings Panel")
        SettingsTable = New SettingsTable

            SettingsTable.Create()
            SettingsWindow.Controls.Add(SettingsTable)

End Sub

Private Sub ViewSettingsPanel_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewSettingsPanel.CheckedChanged

InvokeControl(SettingsWindow, Sub(x) x.Visible = ViewSettingsPanel.Checked)

End Sub

The SettingsTable.Create() method generates a bunch of Labels and TextBoxes based on the contents of the application settings and adds them to the SettingsTable.

When I click on the ViewSettingsPanel checkbox, I get a cross-thread violation error. Any ideas? I would really appreciate it.

  • 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-17T16:08:50+00:00Added an answer on May 17, 2026 at 4:08 pm

    I figured it out. In case anyone else might be running into a similar issue, here was the secret:

    In the SettingsTable class, I have a MakeTable method which looks like this:

    Private Sub MakeTable()
            Me.Visible = False
            Me.Controls.Clear()
            ... add some controls ...
            Me.Visible = True
    End Sub
    

    I did this so that the control wouldn’t flicker if the table was remade while visible. I don’t entirely understand why (from reading, I’m guessing it’s something like the handles for the child controls weren’t being created because they weren’t shown after being created, so IsInvokeRequired evaluated to False when it should have been True). The fix was to do this:

    Private Sub MakeTable()
            If Not IsNothing(Me.Parent) Then If Me.Parent.Visible Then Me.Visible = False
            Me.Controls.Clear()
            ... add some controls ...
            Me.Visible = True
    End Sub
    

    This way, the child controls are “shown” on the invisible SettingsWindow form and their handles are therefore created. Works just fine now!

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

Sidebar

Related Questions

No related questions found

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.