vb.net question about using db connections with threads
Posted on 2011-02-23
If I have a simple class
public class MyClass
private myConn as new sqlconnection
private MyThreadPool(5) as Thread
public sub New()
dim x as integer
for x = 0 to 4
MyThreadPool(x) = New THread(Addressof MyFunction)
private sub MyFunction()
'Do some work in db
Is it safe for all of my threads to use the single instance declared at the class level or do I need to declare one within the MyFunction so each thread has its own instance?
Also, should the connection be opened and closed constantly or just opened once and left open while the thread runs? The threads will pretty much run constantly.