Wie stoppe ich eine Stoppuhr im "Catch" -Block
Posted: 23 Apr 2025, 06:37
Ich versuche, die Reaktionszeit einer Oracle -Abfrage zu erhalten und Stopwatch zu verwenden, um dies zu erreichen.
Ich bin mir nicht sicher, ob es möglich ist, eine Stoppuhr außen zu initialisieren /.
Code: Select all
bool bSuccess = false;
int iRetryCnt = 0;
TimeSpan elasped = TimeSpan.Zero;
while (!bSucess && iRetryCnt < 3)
{
try
{
var timer = System.Diagnostics.StopWatch.StartNew();
timer.Stop();
elapsed = timer.Elapsed;
bSuccess = true;
}
catch
{
iRetryCnt++;
// Assuming db connection timeout happens and it falls here.
// Can't stop timer here and calculate elapsed; "timer" doesn't exist
}
}
Code: Select all
catch