Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
fahminlb33 committed Feb 28, 2021
1 parent c90af1e commit 4a284fb
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/KFlearning/Services/KFlearningApplicationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,23 @@ 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();
}

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)
Expand Down

0 comments on commit 4a284fb

Please sign in to comment.