我有以下方法DWCompare
,我创建了一个方法ErrorsDiscovered
来检查以下方法是否为真。如何避免第二种方法中的错误?
错误:无法将方法组“DWCompare”转换为非委托类型bool。
public static void DWCompare()
{
var performDataHour = DbCall.PerformanceDatas.Where(d =>
d.loggedAt > hourlyBegin && d.loggedAt < hourlyEnd).ToList();
var performanceDataOneDay = DbCall.PerformanceDatas.Where(o =>
o.loggedAt >= dayBegin && o.loggedAt < dayEnd).ToList();
var UniqueFunctionCallsThisHour = performDataHour.GroupBy(g => g.functionName)
.ToLookup(g => g.First().functionName, g => g.Average(gx => gx.functionTime))
.OrderByDescending(g => g.FirstOrDefault()).Take(5);
var UniqueFunctionCallsDay = performanceDataOneDay.ToLookup(g => g.functionName);
performEmailDisplay += "<table>";
performEmailDisplay += "<tr>";
performEmailDisplay += "<td><b>Function</b></td>";
performEmailDisplay += "<td><b>Hourly Average</b></td>";
performEmailDisplay += "<td><b>Daily Average</b></td>";
performEmailDisplay += "</tr>";
foreach (var function in UniqueFunctionCallsThisHour)
{
var key = function.Key;
var HourlyAverage = function.First();
var DailyAverageData = UniqueFunctionCallsDay[key];
double DailyAverage;
if (DailyAverageData != null && DailyAverageData.Count() > 0)
{
DailyAverage = DailyAverageData.Average(f => f.functionTime);
if (HourlyAverage > DailyAverage + DailyAverageData.Select(x =>
x.functionTime).ToList().StandardDeviation())
{
performEmailDisplay += "<tr>";
performEmailDisplay += "<td>" + key + "</td>";
performEmailDisplay += "<td>" + HourlyAverage + "</td>";
performEmailDisplay += "<td>" + DailyAverage + "</td>";
performEmailDisplay += "</tr>";
}
}
}
performEmailDisplay += "</table>";
}
public static void ErrorsDiscovered()
{
if (DWCompare)
{
SendEmail();
}
}
答案 0 :(得分:-2)
使用try catch块,以便在出现错误时不调用sendEmail(),将执行catch块 public static void ErrorsDiscovered(){ 尝试 { DWCompare(); 发送电子邮件(); } 抓住 { //处理错误 }