T
TheVillageCodingIdiot
on my form I have a function that returns a SQL connection depending
on what is selected in a combo box. Once a button is clicked it starts
a backgroundworker thread and Im trying to call the function on the
form to get the SQL connection but getting error that its being
accessed outside the original thread. How do I go about getting the
returned SQL connection into the background worker thread?
example
///////////////Form1.VB//////////////////////////////////
Sub Button1_Click(sender as object, e as eventargs) handles
Button1.Click
Worker = new backgroundworker
Worker.RunWorkerAsync
End Sub
Sub Worker_DoWork(sender as object, e as DoWorkEventArgs) handles
worker.DoWork
Dim class1 as new myClass
class1.Start()
End Sub
Function GetSQLConn() as SQLConnection
Select case combo1.selectedindex
case 0
return sql1
case 1
return sql2
end case
End Function
////////////MyClass.VB////////////////////////////////////////////
Class myClass
Sub Start()
dim comm as SQLConnection = form1.GetSQLConn()
End Sub
End Class
on what is selected in a combo box. Once a button is clicked it starts
a backgroundworker thread and Im trying to call the function on the
form to get the SQL connection but getting error that its being
accessed outside the original thread. How do I go about getting the
returned SQL connection into the background worker thread?
example
///////////////Form1.VB//////////////////////////////////
Sub Button1_Click(sender as object, e as eventargs) handles
Button1.Click
Worker = new backgroundworker
Worker.RunWorkerAsync
End Sub
Sub Worker_DoWork(sender as object, e as DoWorkEventArgs) handles
worker.DoWork
Dim class1 as new myClass
class1.Start()
End Sub
Function GetSQLConn() as SQLConnection
Select case combo1.selectedindex
case 0
return sql1
case 1
return sql2
end case
End Function
////////////MyClass.VB////////////////////////////////////////////
Class myClass
Sub Start()
dim comm as SQLConnection = form1.GetSQLConn()
End Sub
End Class