我有一个WPF应用程序,需要在其中将图像保存到文件系统中,但被告知要谨慎处理文件共享冲突。图像在C#DispatcherTimer中不断被替换。有人告诉我使用Thread.Sleep来使循环不同步。我有几个DispatcherTimers正在运行以创建图像。这是一个合适的解决方案吗?
private void SetUnverifiedCandidates()
{
var unverified = dbCtxt.Candidates
.GroupJoin(
dbCtxt.Results,
candidate => candidate.CandidateNo,
result => result.CandidateNo
(candidate, results) => new { candidate, results }
)
.SelectMany(
joined => joined.results.DefaultIfEmpty(),
(joined, result) => new { joined.candidate, result }
)
.Where(joined => joined.result == null)
.Select(joined => joined.candidate);
foreach (var candidate in unverified)
{
candidate.Status = "Unverified";
}
dbCtxt.SaveChanges();
}
private void SetVerifiedCandidates()
{
var verified = dbCtxt.Candidates
.Join(
dbCtxt.Results,
candidate => candidate.CandidateNo,
result => result.CandidateNo
(candidate, result) => candidate
);
foreach (var candidate in verified)
{
candidate.Status = "Verified";
}
dbCtxt.SaveChanges();
}