private async void Reader_CardAdded(SmartCardReader sender, CardAddedEventArgs args) { await SharedState.LogAsync($"BackgroundScanner ({_taskInstance.InstanceId}): CardAdded event fired."); try { TravelCard card = await CardOperations.ReadTravelCardAsync(args.SmartCard); if (card != null) { await SharedState.LogAsync($"BackgroundScanner ({_taskInstance.InstanceId}): Successful read card."); Task updateCardTask = SharedState.SetAsync(SharedState.LastSeenCard, card.RawValues); await SharedState.LogAsync($"BackgroundScanner ({_taskInstance.InstanceId}): LastSeenCard updated."); Task updateTimestampTask = SharedState.SetAsync(SharedState.LastSeenTimestamp, DateTimeOffset.UtcNow); await SharedState.LogAsync($"BackgroundScanner ({_taskInstance.InstanceId}): LastSeenTimestamp updated."); if (await SharedState.GetAsync <bool>(SharedState.IsApplicationInForeground)) { await SharedState.LogAsync($"BackgroundScanner ({_taskInstance.InstanceId}): Application is in the foreground. Changed Progress value."); _taskInstance.Progress = 2; } else { await SharedState.LogAsync($"BackgroundScanner ({_taskInstance.InstanceId}): Application is in the background. Post toast notification."); PostToastNotification(card); } } } catch (Exception ex) { await SharedState.LogAsync($"BackgroundScanner ({_taskInstance.InstanceId}): Failed to read travel card! Exception: {ex}\nStack trace: {ex.StackTrace}"); } }