From 4fe790259f8e7d3640115438a0b39c01735a66be Mon Sep 17 00:00:00 2001 From: Corey Kosak Date: Sun, 1 Sep 2024 22:52:32 -0400 Subject: [PATCH] slightly cleaner --- csharp/ExcelAddIn/providers/SessionProvider.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/csharp/ExcelAddIn/providers/SessionProvider.cs b/csharp/ExcelAddIn/providers/SessionProvider.cs index d7cbc0c1175..f2471281b90 100644 --- a/csharp/ExcelAddIn/providers/SessionProvider.cs +++ b/csharp/ExcelAddIn/providers/SessionProvider.cs @@ -102,19 +102,16 @@ void CreateSessionBaseInSeparateThread(CredentialsBase credentials) { result = StatusOr.OfStatus(ex.Message); } - // By the time we get here, some time has passed. Decide whether to keep it. + // By the time we get here, some time has passed. Have our results become moot? if (!ReferenceEquals(localLatestCookie, _sharedSetCredentialsCookie.Value)) { - // No, it's stale. Dispose the SessionBase if we have it. - _ = result.AcceptVisitor(sb => { - sb.Dispose(); - return Unit.Instance; - }, - _ => Unit.Instance - ); + // Our results are moot. Dispose of them. + if (result.GetValueOrStatus(out var sb, out _)) { + sb.Dispose(); + } return; } - // Keep it and tell everyone about it (on the worker thread). + // Our results are valid. Keep them and tell everyone about it (on the worker thread). workerThread.Invoke(() => _sessionObservers.SetAndSend(ref _session, result)); }