I have a Site which creates some form of a Report. The whole process takes up to a Minute. To increase the performance I was thinking about turning the synchronous controller into a Asynchronous Controller.
I read through a lot of topics, and guides but I just don’t seem to get the hang of it.
Right now I have a DataSet which has ~15 DataTables. Each of the ~15 DataTables is filled by a different Query.
To convert this Page to a Asynchronous Controller i created a ConnectionManager, created 15 getMethods for each DataTable and each DataTable is in the Model. I also created 2 Controller – one called [Name]Async and one called [Name]Complete. However, now I am stuck.
How do I create ~15 Threads and assign each the Task to populate a DataTable with the getMethod?!
Here some parts of the Code.
Controller
public class RunTableStatisticsController : AsyncController
{
public void RunTableStatisticsAsync()
{
AsyncManager.OutstandingOperations.Increment(2);
// Create Threads who populate RunTableStatisticsModels DataTables
}
public ViewResult RunTableStatisticsComplete(RunTableStatisticsModel voModel)
{
return View(voModel);
}
}
getMethod
public static DataTable getDataTable1()
{
try
{
DataTable dtTemp= new DataTable();
dtTemp.Columns.Add(new DataColumn("ColumnName1", typeof(string)));
dtTemp.Columns.Add(new DataColumn("ColumnName2", typeof(string)));
string sQuery = "select * from 1";
// Instantiate the Command Object
OleDbCommand dbCommand = new OleDbCommand(sQuery, ..MyConnectionManager.Connection);
dbCommand.CommandType = CommandType.Text;
// Execute the Stored Procedure
OleDbDataReader dr = dbCommand.ExecuteReader();
while (dr.Read())
{
DataRow row = dtTemp.NewRow();
row["ColumnName1"] = dr["ColumnName1"]);
row["ColumnName2"] = dr["ColumnName2"];
dtTemp.Rows.Add(row);
}
return dtTemp;
}
catch (Exception ex)
{
throw new Exception("Error: Reading database.", ex);
}
}
Correspondend I do have in my Model
public DataTable dtTable1{ get; set; }
And then I have a View which has Telerik Grid Extensions which will be filled by the Data.
You could use the TPL to parallelize the retrieval of those DataTables. Here’s an example with 2, if you have more, you might consider using collections of DataTables: