I have the following code that runs to start my table calculations (the table calculations fire off a few queries returning thousands of rows). When my app just runs one instance, things are fine, but 2 or more then the server slows done and I start to get errors.
Should I turn this code into threads? How is that done?
private static object _lock = new object();
private void RunTable(string outputType, string _outputDataType) {
Server.ScriptTimeout = 300;
string returnCode = string.Empty;
lock (_lock)
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MainDll"].ToString()))
{
connection.Open();
using (SqlCommand command = new SqlCommand(sql.ToString(), connection))
{
command.CommandType = CommandType.Text;
command.CommandTimeout = 300;
returnCode = (string)command.ExecuteScalar();
Dispose();
}
Dispose();
}
}