I'm creating a Windows Form application which Dynamically creates controls based on data pulled from a Database.
I have the code working great in the background which loads the data from the database and applies it to variables, the problem I am having is when trying to create the controls using this data, I get a multi-threading error ( Additional information: Cross-thread operation not valid: Control 'flowpanelMenuRules' accessed from a thread other than the thread it was created on.)
I'm using the BackgroundWorker_DoWork event and the code that fails is the following:
Me.flowpanelMenuRules.Controls.Add(PanelRule(i))
The code before is a simple loop going through the variable (which is pulled from the database) and gathering the information.
Has anybody had any experience in safely invoking the above line? I just can't seem to get it to work at all :(
Thanks for the help, I can post more code if needed.