Multithreading using VB.net Throws error -
am new vb.net multithreading.
currect me if i'm doing wrong.
what i'm trying :
user's needs put serial no's textbox program needs pick model , warranty infomation vendor website when user hit search button.
my windows form have 2 textbox's , 2 webbrowsers , 1 datagridview control.
what i'm trying when user hit search buttom code needs below things
thread1: pick serial no textbox1 , needs information web using webbrowser1 thread2:pick serial no textbox2 , needs information web using webbrowser2
my code looks
dim thread1 system.threading.thread dim thread2 system.threading.thread private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click thread1 = new system.threading.thread(addressof thread11) thread1.start() thread2 = new system.threading.thread(addressof thread22) thread2.start() end sub private sub form1_load(byval sender system.object, byval e system.eventargs) handles mybase.load me.checkforillegalcrossthreadcalls = false end sub sub thread11() ' takes serial no text1 , searches information using webbrowser1 goes here end sub sub thread22() ' takes serial no text2 , searches information using webbrowser2 goes here end sub
but i'm getting below error messange when debug code
an error occurred creating form. see exception.innerexception details. error is: activex control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot instantiated because current thread not in single-threaded apartment.
it great if tell i'm doing wrong , needs done ,
thanks sathish
when create threads, try set apartment state.
thread1 = new system.threading.thread(addressof thread11) thread1.setapartmentstate(apartmentstate.sta) thread1.start() thread2 = new system.threading.thread(addressof thread22) thread2.setapartmentstate(apartmentstate.sta); thread2.start()
Comments
Post a Comment