I am creating a Windows Form application that dynamically creates controls based on data retrieved from a database.
I have code that runs fine in the background that loads data from a database and applies it to variables, the problem I am facing is trying to create controls using this data, I get a multi-threaded error (additional information: operation Cross-thread invalid: "flowpanelMenuRules" is controlled from a thread other than the thread in which it was created.)
I am using the BackgroundWorker_DoWork event, and the failed code is as follows:
Me.flowpanelMenuRules.Controls.Add(PanelRule(i))
The before code is a simple loop through a variable (which is retrieved from the database) and gathering information.
Does anyone have experience safely calling the above line? I just can't get it to work at all :(
Thanks for the help, I can send more code if necessary.
source share