Hi
I have below code & it slows down the performance
for(each colum in loop)
BALSessionDeliveryParticipant bALSessionDeliveryParticipant = new BALSessionDeliveryParticipant();
List objStudentList = bALSessionDeliveryParticipant.GetSessionDeliveryDetailsByCalendarID(colum.SessionDeliveryCalendarID);
BALStudents bALStudents = new BALStudents();
if (objStudentList != null)
{
foreach (var colum1 in objStudentList)
{
StudentDetail objResult = bALStudents.GetStudentDetailByLoginID(Convert.ToInt32(colum1.StudentID));
if (colum1.PresentInSession == true)
htmlTable.Append("" + objResult.Name + "");
else
{
if (colum1.OnBreak == false)
htmlTable.Append("" + objResult.Name + "");
else
htmlTable.Append("" + objResult.Name + "");
}
}
}
Thanks
Ramco RamcoPosted Apr 1, 2023, 5:00 AM
Hi Naimish
Can u pls provide some sample
Thanks
Naimish MakwanaPosted Apr 1, 2023, 4:54 AM
There could be several reasons why this code is slowing down performance. One possible issue is that it's making multiple calls to the database within a loop, which can be quite expensive. Another issue could be that the code is creating a new object and allocating memory on each iteration of the loop.
Here are a few suggestions to optimize the code:
Minimize database calls: Instead of making a database call for each column in the loop, try to consolidate the calls by passing all the necessary parameters in a single call. This can significantly reduce the number of database calls and improve performance.
Reuse objects: Rather than creating a new instance of the BALSessionDeliveryParticipant and BALStudents objects on each iteration of the loop, try to reuse existing objects by creating them outside the loop and passing them as parameters.
Thanks
Naimish