Reputation: 147
I have multithreaded application that needs an access to MSSQL. I have created a class with static methods where each method looks like this:
public static int [] Login(string [] LoginDetails)
{
using (SqlConnection connection = new SqlConnection(CS))
{
}
Is that correct? I am not experienced in multithreading but I guess each thread will run "copy" of this static method with its variables and so they will not be shared. I assume if I declared static members (like sqlConnection) on the class level and made it static, it would be shared and thus it would cause concurrent access issues.
Upvotes: 2
Views: 140
Reputation: 1503639
It's not that it "copies" the method itself, but each method invocation (whether in the same thread recursively or different threads) will indeed get its own separate set of local variables.
So long as none of the data here is shared between threads in a mutable way, you should be fine.
(As an aside, it's more idiomatic to include the array part of a type alongside the name, with no spaces - so int[]
instead of int []
.)
Upvotes: 3