From 4a284fbc7fe3f9db94338adf6bceaf755d134e39 Mon Sep 17 00:00:00 2001 From: fahminlb33 Date: Sun, 28 Feb 2021 22:40:01 +0700 Subject: [PATCH] Optimize code --- .../Services/KFlearningApplicationContext.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/KFlearning/Services/KFlearningApplicationContext.cs b/src/KFlearning/Services/KFlearningApplicationContext.cs index 8aa790c..3486b7c 100644 --- a/src/KFlearning/Services/KFlearningApplicationContext.cs +++ b/src/KFlearning/Services/KFlearningApplicationContext.cs @@ -7,15 +7,13 @@ namespace KFlearning.Services { public class KFlearningApplicationContext : ApplicationContext { - private readonly ITelemetryService _telemetry; - private Form _mainForm; + private readonly Form _mainForm; public KFlearningApplicationContext(ITelemetryService telemetryService, StartupForm form) { - _telemetry = telemetryService; _mainForm = form; - Task.Run(() => _telemetry.Load()); + Task.Run(() => telemetryService.Load()); _mainForm.HandleDestroyed += OnFormDestroy; _mainForm.Show(); @@ -23,11 +21,9 @@ public KFlearningApplicationContext(ITelemetryService telemetryService, StartupF private void OnFormDestroy(object sender, EventArgs e) { - if (sender is Form form && !form.RecreatingHandle) - { - form.HandleDestroyed -= OnFormDestroy; - OnMainFormClosed(sender, e); - } + if (!(sender is Form form) || form.RecreatingHandle) return; + form.HandleDestroyed -= OnFormDestroy; + OnMainFormClosed(sender, e); } protected override void Dispose(bool disposing)