diff --git a/PrimaryFormParts/PrimaryForm.SQLSearch.cs b/PrimaryFormParts/PrimaryForm.SQLSearch.cs index 7ca29a1..5df74c5 100644 --- a/PrimaryFormParts/PrimaryForm.SQLSearch.cs +++ b/PrimaryFormParts/PrimaryForm.SQLSearch.cs @@ -84,6 +84,7 @@ namespace DualScreenDemo{ connection.Close(); stopwatch.Stop(); Console.WriteLine($"MyDB 連線已關閉!執行時間: {stopwatch.ElapsedMilliseconds} 毫秒"); + writeLogforSearchTime(stopwatch.ElapsedMilliseconds); Console.WriteLine($"查詢到 {searchResults.Count} 筆資料。"); } @@ -97,7 +98,9 @@ namespace DualScreenDemo{ using (var connection = new MySqlConnection(connectionString)) { + Stopwatch stopwatch = new Stopwatch(); connection.Open(); + stopwatch.Start(); Console.WriteLine("MyDB 連線成功!"); using (var command = new MySqlCommand(query, connection)) @@ -121,11 +124,23 @@ namespace DualScreenDemo{ } } connection.Close(); - Console.WriteLine("MyDB 連線已關閉!"); + stopwatch.Stop(); + Console.WriteLine($"MyDB 連線已關閉!執行時間: {stopwatch.ElapsedMilliseconds} 毫秒"); + writeLogforSearchTime(stopwatch.ElapsedMilliseconds); + Console.WriteLine($"查詢到 {searchResults.Count} 筆資料。"); } return searchResults; } + private int countforSearch = 0; + private void writeLogforSearchTime(long elapsedMs){ + + countforSearch++; + + string logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "txt", "searchTimeLog.txt"); + string data = $"{countforSearch}, {elapsedMs} " + Environment.NewLine; + File.AppendAllText(logFilePath, data); + } } } \ No newline at end of file