I am having performance issues when starting a Windows service, the first round my lstSps is long (about 130 stored procedures). Is there a way to speed this up (with the exception of speeding up stored procedures)?
When the foreach is finished and goes into the second round, it goes faster, because there will not be much return on TimeToRun (). But, my concern is the first time there are many more stored procedures to run.
I have a question about creating an array and a for loop, since I read that it works faster, but I believe the problem is that the procedures take a lot of time. Can I build it better? Maybe use multiple threads (one for each execution) or something like that?
I would like some tips :)
EDIT: just to clarify, this HasResult () method executes SP: s and does a time search.
lock (lstSpsToSend)
{
lock (lstSps)
{
foreach (var sp in lstSps.Where(sp => sp .TimeToRun()).Where(sp => sp.HasResult()))
{
lstSpsToSend.Add(sp);
}
}
}
while (lstSpsToSend.Count > 0)
{
Sp sp;
lock (lstSpsToSend)
{
sp = lstSpsToSend[0];
lstSpsToSend.RemoveAt(0);
}
try
{
}
catch (Exception e)
{
Thread.Sleep(30000);
}
}
source
share