Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
one of my form takes hell lot of time to load, reason being the class i am using is intantiated before the form could load.
now for the time the form takes to load, i display a loading image(on a form) using background worker.
Now after the original form is intatiated in the backgroundworker, i am trying to show the form in a different function where i assign it to an MDIPArent form.
here i get the error 'cross thread operation not valid: control 'form' accessed from a thread other than the thread it wasa created on'.
kindly help as evrything else is working fine xcept dis..
thanking you in anticipation.
Posted
Comments
E.F. Nijboer 21-May-13 5:39am    
Have you googled it? This is a very common beginners error. You need to invoke the UI thread if you want to update UI elements.
aryan_85 21-May-13 5:41am    
of corse i did...but in vain.
Do u knw d way to access UI elements after dey r created/instantiated in backgroundworker??
:-(
aryan_85 21-May-13 6:42am    
thanx Nijboer...
found something that worked perfectly..
ur comment helped me to guide/lead to the real cause of the error
:-)
E.F. Nijboer 21-May-13 8:59am    
Nice to help you find it :-)

1 solution

To access the controls that r created in the background-worker..use the invoke method of the controls-

below code is in DO_WORK() method of backgroundworker

'form_name is a string argument passed to RunWorkerAsync method
dim frm as form = activator.createinstance(form_name,form)

'here "me" is d MDIPARENT of d form "frm" which will be assgned in a method below

Me.Invoke(New Action(Function()
ShowForm(frm) 'ShowForm is a method that displays the form "frm" by assigning a MDIParent to it
End Function))



it worked perfectly fine
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900