【发布时间】:2010-09-06 22:08:22
【问题描述】:
这是我的代码
void fixInstellingenTabel(object source, ElapsedEventArgs e)
{
NASDataContext _db = new NASDataContext();
List<Instellingen> newOnes = new List<Instellingen>();
List<InstellingGegeven> li = _db.InstellingGegevens.ToList();
foreach (InstellingGegeven i in li) {
if (_db.Instellingens.Count(q => q.INST_LOC_REF == i.INST_LOC_REF && q.INST_LOCNR == i.INST_LOCNR && q.INST_REF == i.INST_REF && q.INST_TYPE == i.INST_TYPE) <= 0) {
// There is no item yet. Create one.
Instellingen newInst = new Instellingen();
newInst.INST_LOC_REF = i.INST_LOC_REF;
newInst.INST_LOCNR = i.INST_LOCNR;
newInst.INST_REF = i.INST_REF;
newInst.INST_TYPE = i.INST_TYPE;
newInst.Opt_KalStandaard = false;
newOnes.Add(newInst);
}
}
_db.Instellingens.InsertAllOnSubmit(newOnes);
_db.SubmitChanges();
}
基本上,InstellingGegevens 表由另一台服务器的某个过程填充。 然后我需要做的是检查该表中是否有新记录,并在 Instellingens 中填写新记录。
此代码在 15k 条记录上运行大约 4 分钟。我该如何优化它?还是存储过程的唯一方式?
此代码在计时器中运行,每 6 小时运行一次。如果存储过程是最好的,我如何在计时器中使用它?
Timer Tim = new Timer(21600000); //6u
Tim.Elapsed += new ElapsedEventHandler(fixInstellingenTabel);
Tim.Start();
【问题讨论】:
标签: c# asp.net linq-to-sql optimization timer